写一个方法,给一个字符串数组排序,要求优先按照字符串长度排序,如果字符串长度相同,再按照字符串大小排序。
public class MyTest01 {
public static void main(String[] args) {
String[] arr = new String[]{"afs","aafsaf","rwr","daaa"};
Arrays.sort(arr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.length() != o2.length() ? Integer.compare(o1.length(),o2.length()):o1.compareTo(o2);
}
});
System.out.println(Arrays.toString(arr));
}
}