java sort
1 MyString mySs[]=new MyString[result.length];//创建自定义排序的数组 2 for (int i = 0; i < result.length; i++) { 3 mySs[i]=new MyString(result[i]); 4 } 5 Arrays.sort(mySs);//排序 6 7 for(int j=0;j<mySs.length;j++){ 8 result[j]=mySs[j].s; 9 } 10 11 12 class MyString implements Comparable<MyString>{ 13 public String s;//包装String 14 public MyString(String s) { 15 this.s = s; 16 } 17 18 @Override 19 public int compareTo(MyString o) { 20 if(o==null||o.s==null) return 1; 21 if(s.length()>o.s.length()) return 1; 22 else if(s.length()<o.s.length()) return -1; 23 return s.compareTo(o.s); 24 } 25 }