I am trying to remove duplicates from an ArrayList. But I keep getting this UnsupportedOperationException
public static void removeDuplicates(List<Integer> list) {
Collections.sort(list);
for(int i = 0; i<list.size();i++) {
if(list.get(i)== list.get((i+1))) {
list.remove(i+1);
}
}
}
One thing I cannot create a new list and change it because I shouldn't return anything. I have to change the list in place.