I need to add objects to a list (with List semantics) while keeping all objects in the list unique. I figured LinkedHashSet would do, but the “re-insert” clause breaks this:
LinkedHashSet<String>list = new LinkedHashSet<String>();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("a");
System.out.println (list);
Output from the above is: [a, b, c], not [b, c, a] as I would like it.
Is there any such data-structure in Java which handles this case?
try
output