Last active
November 16, 2017 05:33
-
-
Save zunpiau/65a9fd03ac2d07da6d72abcc96eef1f3 to your computer and use it in GitHub Desktop.
`.`分割后字典排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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