How to maintain a Unique List in Java?

前端 未结 7 1031
滥情空心
滥情空心 2020-12-04 11:53

How to create a list of unique/distinct objects (no duplicates) in Java?

Right now I am using HashMap to do this as the key is o

7条回答
  •  遥遥无期
    2020-12-04 12:26

    You could just use a HashSet to maintain a collection of unique objects. If the Integer values in your map are important, then you can instead use the containsKey method of maps to test whether your key is already in the map.

提交回复
热议问题