package p_learn;
import java.util.*;class IntSort implements Comparator{
public int compare(Object o1,Object o2){
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;
return i1.compareTo(i2)> 0 ? -1 : (i1.compareTo(i2) == 0) ? 0 : 1; }}public class Array2 { public Array2() {}
public static void main(String[] args)
{ Integer [] n ={new Integer(2),new Integer(6),
new Integer(3),new Integer(2),new Integer(6)};
Arrays.sort(n,new IntSort());
for(int i=0;i<n.length;i++)
System.out.println(n[i]);
}
}
import java.util.*;class IntSort implements Comparator{
public int compare(Object o1,Object o2){
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;
return i1.compareTo(i2)> 0 ? -1 : (i1.compareTo(i2) == 0) ? 0 : 1; }}public class Array2 { public Array2() {}
public static void main(String[] args)
{ Integer [] n ={new Integer(2),new Integer(6),
new Integer(3),new Integer(2),new Integer(6)};
Arrays.sort(n,new IntSort());
for(int i=0;i<n.length;i++)
System.out.println(n[i]);
}
}
Sorts the specified array of objects according to the order induced by the specified comparator.