Possible Duplicate:
More efficient way to remove elements from an array list
I have developed an array list
ArrayList<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("3");
list.add("5");
list.add("6");
list.add("7");
list.add("7");
list.add("1");
list.add("10");
list.add("2");
list.add("12");
Now what I was trying to remove duplicate elements from it but this time I do not want to convert it into set or having an iteration loop in list itself , what I was trying any built in method of List or Collections class that will remove the duplicates or is there any other way to achieve this , please advise, thanks in advance
There is simply no solution for what you’re asking. Don’t use
Listin the first place – useSet. If you’re concerned about preserving order of insertions, there isLinkedHashSet. If you need to returnListfrom the method – useLinkedHashSet, and then convert it intoList; or consider returningCollection, notList.