I am removing duplication from arraylist. To do this, first add all the items of arraylist to a HashSet.
HashSet takes only unique items.
Finally, take HashSet items to the arraylist.
List arrayList = new ArrayList<>();
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
arrayList.add("A");
Set hashSet = new HashSet<>();
hashSet.addAll(arrayList);
arrayList.clear();
arrayList.addAll(hashSet);
0 Comment(s)