package shopping.cart;
import java.util.*;
public class Demo3 {
public static void main(String[] args) {
int[] arr = {4,2,4,6,1,2,4,7,8,2,4,4,2};
TreeSet<Integer> ts = new TreeSet<Integer>(new com());
for(int i = 0; i < arr.length; i ++)
ts.add(new Integer(arr[i]));
Iterator<Integer> it = ts.iterator();
while(it.hasNext())
{
System.out.print(it.next());
}
}
}
class com implements Comparator
{
public int compare(Object o1, Object o2) {
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;
if(i1.equals(i2)){
System.out.print((i1)+"::"+(i2)+" ");
return 0;
}
return 1;
}
}
结果:4::4 4::4 2::2 2::2 4::4 426147842
|
|