I am trying to sort a list in reverse order and then removing duplicates. I am using the following code.
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(3);
list.add(3);
list.add(2);
list.add(3);
list.add(2);
Collections.sort(list, Collections.reverseOrder());
System.out.println(list);
Set<Integer> set = new HashSet<>(list);
System.out.println(set);
}
It works fine but the order is again changed when converted to a Set. What to do to preserve the order