Skip to content

Instantly share code, notes, and snippets.

@zunpiau
Last active November 16, 2017 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zunpiau/65a9fd03ac2d07da6d72abcc96eef1f3 to your computer and use it in GitHub Desktop.
Save zunpiau/65a9fd03ac2d07da6d72abcc96eef1f3 to your computer and use it in GitHub Desktop.
`.`分割后字典排序
List<String> arr = Arrays.asList ("a.b.c", "a.b", "a.ab", "c");
arr.sort ((o1, o2) -> {
String[] spilt1 = o1.split ("\\.");
String[] spilt2 = o2.split ("\\.");
int compare = 0;
for (int i = 0; i < spilt1.length && i < spilt2.length; i++) {
compare = spilt1[i].compareTo (spilt2[i]);
if (compare != 0)
break;
}
compare = (compare == 0) ? Integer.compare (spilt1.length, spilt2.length) : compare;
return compare;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment