import java.util.*;
public class csdntest3{
@SuppressWarnings("unchecked")
public static void main(String[] args){
List<Integer> list = new ArrayList<Integer>();
for(int i = 1; i <=5; i++){
list.add(i);
}
Collections.sort(list, new Comparatorsort());
for(int i = 0; i < list.size(); i++){
System.out.println(list.get(i));
}
}
}
class Comparatorsort implements Comparator{
public int compare(Object o1,Object o2)
{
Integer str1=(Integer)o1;
Integer str2=(Integer)o2;
if(str1.compareTo(str2)>0)
return -1;
if(str1.compareTo(str2)<0)
return 1;
return 0;
}
}
|