Suppose: list = ["be", "be", "is", "not", "or", "question", "that", "the", "to", "to"]
public static void removeDuplicates(ArrayList<String> list) {
for(int i = 0; i < list.size(); i++) {
String s = list.get(i);
for(int j = 0; j < list.size() - 1; j++) {
String s2 = list.get(j);
if(s2.equals(s)); {
list.remove(j + 1);
}
}
}
}
When I debug it, s2.equals(s)
seems to be returning true all the time when s2 and s does not equal to each other at all. What am I doing wrong?