Set ts = new TreeSet(); String[] v = {"1", "3", "1", "2"}; for(int i=0; i< v.length; i++) { ts.add(v[i]); } Iterator it = (Iterator) ts.iterator(); while(it.nextInt()) { System.out.println(it.next()+" "); } }
Set set = new TreeSet(new Comparator() { public int compare(String one, String other) { // implement } });
- TreeSet sorts the order and don't accept null