Consider the following data field and partially defined method. private ArrayLis
ID: 3643425 • Letter: C
Question
Consider the following data field and partially defined method.private ArrayList<String> people;
public void removeDups(String target)
{ // code not shown }
The method removeDups is intended to remove all instances of target that occur in people except the first, leaving the first instance in the same relative position. Which of the following correctly implements the method removeDups
**ANSWER CHOICES**
A.) for(int k = 0; k < people.size(); k++)
{
if(people.get(k).equals(target))
people.remove(k);
}
B.) int k = 0;
while(k < people.size())
{
if(people.get(k).equals(target))
people.remove(k);
else
k++;
}
C.) int k = 0;
while(k < people.size() && !people.get(k).equals(target))
k++;
for(int j = k+1; j < people.size(); j++)
{
if(people.get(k).equals(target))
people.remove(k);
D.) int k = 0;
while(k < people.size() && !people.get(k).equals(target))
k++;
while(k < people.size())
{
if(people.get(k).equals(target))
people.remove(k);
else
k++;
}
E.) int k = 0;
while(k < people.size() && !people.get(k).equals(target))
k++;
k++;
while(k < people.size())
{
if(people.get(k).equals(target))
people.remove(k);
else
k++;
}
Explanation / Answer
C.) int k = 0; while(kRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.