Comparable

LCOTCOF 发布于 2014/12/17 19:33
阅读 52
收藏 0
public class GenericSort {
public static void main(String[] args){
Integer[] intArray={new Integer(2),new Integer(5),new Integer(1),new Integer(-8),
new Integer(-3)};
Double[] doubleArray={new Double(2.3),new Double(5.8),new Double(1.5),
new Double(-2.3),new Double(-0.3)};
String[] stringArray={"Tom","Jim","Lily","A"};

sort(intArray);
sort(doubleArray);
sort(stringArray);

printList(intArray);
printList(doubleArray);
printList(stringArray);
}
public static void sort(Comparable[] list){
Comparable currentMin;

for(int i=0;i<list.length-1;i++){
currentMin=list[i];

for(int j=i+1;j<list.length;j++){
if(currentMin.compareTo(list[j])>0){
currentMin=list[j];
list[j]=list[i];
list[i]=currentMin;
}
}
}
}

public static void printList(Object[] list){
for(int i=0;i<list.length;i++){
System.out.print(list[i]+" ");
System.out.println();
}
}

}

sort方法中有几个warning,如何消除?

加载中
返回顶部
顶部