Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 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. Collections.sort(cities,new Comparator<String>(){
  6. public int compare(String s1,String s2){
  7. if (s1.length() != s1.length())
  8. s1.length() - s2.length();
  9. else
  10. s1.toCharArray() - s2.toCharArray();
  11. }
  12. });
  13. cities.sort((city, subCity) -> city.compareToIgnoreCase(subCity)); // First by length, second by characters
  14.  
  15. for (String s: cities) {
  16. System.out.print(s + " ");
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement