Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SortStringIgnoreCase {
- public static void main(String[] args) {
- java.util.List<String> cities = java.util.Arrays.asList
- ("Atlanta", "Savannah", "new York", "dallas", "Macon", "Columbia");
- Collections.sort(cities,new Comparator<String>(){
- public int compare(String s1,String s2){
- if (s1.length() != s1.length())
- s1.length() - s2.length();
- else
- s1.toCharArray() - s2.toCharArray();
- }
- });
- cities.sort((city, subCity) -> city.compareToIgnoreCase(subCity)); // First by length, second by characters
- for (String s: cities) {
- System.out.print(s + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement