Remove duplicates from an ArrayList?
arrays, java, unique
Solution
Better use a HashSet. If not possible then you can use a temporary `HashSet` for this.
ArrayList a= new ArrayList();
HashSet hs = new HashSet();
hs.addAll(a); // willl not add the duplicate values
a.clear();
a.addAll(hs); // copy the unique values again to arraylist
Problem
How to remove duplicates from an `ArrayList`? I have `getCcnptags` array as `[java,php,c++,c,java,php]` which i am getting from bean array, and I am giving hyper link to each array variable, but I want to remove duplicates before adding hyper link to it, does it possible to add any code in my below code to remove duplicates. ``` for(int k=0;k<name.getCcnptags().size();k++) { String tag=name.getCcnptags().get(k); if(k!=name.getCcnptags().size()-1) { tag=tag+","; } %> <a href='#'><%=tag%></a> } ```