public class Test {
public static void main(String[] args) {
String[] c = new String[]{"F","a","f","h","A","g","K"};
String tmp = null;
for(int i=0 ; i < c.length ; ++i){
for(int j=0; j <c.length - i - 1; ++j){
if(compare(c[j], c[j+1])>0){
tmp = c[j];
c[j] = c[j + 1];
c[j + 1] = tmp;
}
}
}
for(String str:c) {
System.out.println(str);
}
}
public static int compare(String s1, String s2) {
if(s1.toLowerCase().compareTo(s2.toLowerCase()) != 0)//首先忽略大小写比较
return s1.toLowerCase().compareTo(s2.toLowerCase());
if(s1.equals(s2))
return 0;
else
return s1.compareTo(s2);
}
}
已有的代码 希望对你有帮助 |