How to maintain a Unique List in Java?

前端 未结 7 1030
滥情空心
滥情空心 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:33

    You may want to use one of the implementing class of java.util.Set Interface e.g. java.util.HashSet collection class.

    A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

提交回复
热议问题