Removing Duplicate Values from ArrayList

后端 未结 18 1320
无人及你
无人及你 2020-11-30 03:24

I have one Arraylist of String and I have added Some Duplicate Value in that. and i just wanna remove that Duplicate value So how to remove it.

Here Example I got o

18条回答
  •  无人及你
    2020-11-30 04:03

         public List removeDuplicates(List list) {
        // Set set1 = new LinkedHashSet(list);
        Set set = new TreeSet(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                     if(((Contact)o1).getId().equalsIgnoreCase(((Contact)2).getId()) ) {
                    return 0;
                }
                return 1;
            }
        });
        set.addAll(list);
        final List newList = new ArrayList(set);
        return newList;
    }
    

提交回复
热议问题