Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting an error for my code that says: The number of elements expected is

ID: 3746459 • Letter: I

Question

I am getting an error for my code that says: The number of elements expected is <2> but was <0>.

Here is the test code line: assertEquals("The number of elements is incorrect", 2, actual.size());

This is the entire method:

public static ArrayList<String> getDifference(ArrayList<String> one, ArrayList<String> two) {

ArrayList<String> three = new ArrayList<String>();

for (int i = 0; i < one.size(); i++) {

if (two.contains(one.get(i))) {

continue;

}

if (three.contains(one.get(i))) {

continue;

}

else {

three.add(one.get(i));

}

for (int j = 0; j < two.size(); j++) {

if (one.contains(two.get(j))) {

continue;

}

if (three.contains(two.get(j))) {

}

else {

three.add(two.get(j));

}

}

}

return three;

}

Explanation / Answer

public static ArrayList getDifference(ArrayList one, ArrayList two) { ArrayList three = new ArrayList(); for (int i = 0; i