Hi, How to store unique elements in list which already contains duplicate elements in it I mean I want to retrieve unique elements from list where it has duplicate values?
Why use a List if you need to store unique objects? If you have a list with duplicated values in it and you want just the unique values, add the contents of the List to a Set. [ July 28, 2008: Message edited by: Paul Sturrock ]
Hi
Look this code. Removes the duplicate and returns List object.
org.apache.commons.collections.list.SetUniqueList is from apache common-collection API.
List list =new ArrayList();
list.add("ONE");
list.add("ONE");
list.add("TWO");
list.add("TWO");
Set set = new HashSet();
List l = SetUniqueList.decorate(list); System.out.println(l);