How to maintain a Unique List in Java?
问题 How to create a list of unique/distinct objects (no duplicates) in Java? Right now I am using HashMap<String, Integer> to do this as the key is overwritten and hence at the end we can get HashMap.getKeySet() which would be unique. But I am sure there should be a better way to do this as the value part is wasted here. 回答1: You can use a Set implementation: Some info from the JAVADoc: A collection that contains no duplicate elements . More formally, sets contain no pair of elements e1 and e2