问题
I have a list of list:
List<List<Integer>> myList = new ArrayList<>();
What would be the best way to remove the duplicated list in myList?
For example, in the following list of list:
[[-1,0,1],[-1,-1,2],[-1,0,1]]
I would like to reduce it to:
[[-1,0,1],[-1,-1,2]]
Thanks!
回答1:
The easiest way is to copy it into an order-preserving set (or, more generally, any kind of set, if you don't care about the ordering), and then back into the list:
myList = new ArrayList<>(new LinkedHashSet<>(myList));
回答2:
Use a Set instead of a list. Sets do not allow duplicates. What is the difference between Set and List?
来源:https://stackoverflow.com/questions/46531811/java-best-way-to-remove-duplicated-list-in-a-list