File[]按拼音排序

先定义一个内部类

public static class PyComparator implements Comparator {

public int compare(Object arg0, Object arg1) {

Collator collator = Collator.getInstance(new Locale(“zh”));

return collator.compare(arg0.toString(), arg1.toString());

}

}

然后这样排序:

Arrays.sort(files, new PyComparator());

比较奇怪的是OuterClass的静态方法中对非静态的内部对象实例化方法: new OuterClass().new InnerClass()

Comments are closed.