Question: Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of integers. For example, if nums contains {

Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of integers. For example, if nums contains {1,2,2,3,4,3,5,5,6}, then after executing remDups(nums), nums should contain {1,2,3,4,3,5,6}.
public static void remDups(ArrayList nums)
{
for (int j =0; j < nums.size()-1; j++)
{
if (nums.get(j).equals(nums.get(j +1)))
{
nums.remove(j);
j++;
}
}
}
The code does not always work as intended. Which of the following lists can be passed to remDups to show that the method does NOT work as intended?
A.{1,1,2,3,3,4,5}
B.{1,2,2,3,3,4,5}
C.{1,2,2,3,4,4,5}
D.{1,2,2,3,4,5,5}
E.{1,2,3,3,4,5,5}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!