import java.util.*;
class TreeSetTest2
{
public static void main(String[] args)
{
TreeSet ts = new TreeSet(new myCompare());
String s = "90 -7 0 18 2 45 4";
String[] str = s.split(" ");
for(int x = 0 ; x < str.length ; x++)
{
ts.add(str[x]);
}
Iterator it = ts.iterator();
while(it.hasNext())
{
sop(it.next());
}
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
class myCompare implements Comparator
{
public int compare(Object o1 , Object o2)
{
String s1 = (String)o1;
String s2 = (String)o2;
int num = new Integer(Integer.parseInt(s1)).compareTo(new Integer(Integer.parseInt(s2)));
return num;
} |