import java.util.*;
class Test
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add("java01");
al.add("java02");
al.add("java01");
al.add("java02");
al.add("java01");
al.add("java03");
sop(al);
al = singleElement(al);
sop(al);
}
public static ArrayList singleElement(ArrayList al)
{
ArrayList newAl = new ArrayList();
for(Iterator it = al.iterator(); it.hasNext();)
{
Object obj = it.next();
if(!newAl.contains(obj))
{
newAl.add(obj);
}
}
return newAl;
}
} |