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");
- cities.sort((s1,s2) -> {
- if (s1.length() != s2.length())
- return s1.length() - s2.length(); // Sort by Length
- else
- return s1.toCharArray().length - s2.toCharArray().length; // Second, Sort by Characters if the lengths are the same
- }); // First by length, second by characters
- for (String s: cities) {
- System.out.print(s + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement