class SortByString implements Comparator<String> {
public int compare(String s1, String s2) {
//return o1.length()-o2.length();
int flag = -1;
int min = s1.length()<s2.length()?s1.length():s2.length();
for(int i=0;i<min;i++){
if(s1.charAt(i)<s2.charAt(i)){
flag = -1;
break;
}else{
flag = 1;
break;
}
}
return s1.length()-s2.length();
}
}
public void test(){
List<String> strlists = new ArrayList<String>();
strlists.add("c");
strlists.add("abc");
strlists.add("b");
Collections.sort(strlists,new SortByString());
}
java ArrayList 排序
最新推荐文章于 2024-04-08 21:27:08 发布