How to maintain a Unique List in Java?

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

    I do not know how efficient this is, However worked for me in a simple context.

    List<int> uniqueNumbers = new ArrayList<>();
    
       public void AddNumberToList(int num)
        {
            if(!uniqueNumbers .contains(num)) {
                uniqueNumbers .add(num);
            }
        }
    
    0 讨论(0)
提交回复
热议问题