The first method finds the duplicate and the second removes it. I tried the following code and it does not work. I don't understand why. to be done using two methods. When I call the methods, they do not remove the duplicates. The arraylist is unchanged. I want to remove the duplicates using two methods.
public static int find(ArrayList<String> s, int i) {
for (int j = i + 1; j < s.size(); j = j + 1) {
if (s.get(i) == s.get(j)) {
return j;
}
}
return -1;
}
public static void removeDuplicates(ArrayList<String> s) {
for (int i = 0; i < s.size(); i = i + 1) {
int foundAt = (find(s, i));
if (foundAt >= 0) {
s.remove(i);
}
}
}