如果您不想添加对番石榴的依赖关系(根据迈克尔的回答),那么此比较器是等效的:
private static Comparator<String> ALPHABETICAL_ORDER = new Comparator<String>() { public int compare(String str1, String str2) { int res = String.CASE_INSENSITIVE_ORDER.compare(str1, str2); if (res == 0) { res = str1.compareTo(str2); } return res; }};Collections.sort(list, ALPHABETICAL_ORDER);而且我认为它易于理解和编码…
该方法的最后4行可以更简洁地编写如下:
return (res != 0) ? res : str1.compareTo(str2);



