Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class SortStringIgnoreCase {
  2. public static void main(String[] args) {
  3. java.util.List<String> cities = java.util.Arrays.asList
  4. ("Atlanta", "Savannah", "new York", "dallas", "Macon", "Columbia");
  5. cities.sort((s1,s2) -> {
  6. if (s1.length() != s2.length())
  7. return s1.length() - s2.length(); // Sort by Length
  8. else
  9. return s1.toCharArray().length - s2.toCharArray().length; // Second, Sort by Characters if the lengths are the same
  10. }); // First by length, second by characters
  11.  
  12. for (String s: cities) {
  13. System.out.print(s + " ");
  14. }
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement