import java.io.*; import java.util.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { int ai = 0, bi = 0; while (ai < a.length() && bi < b.length()) { int an = 0; while (ai < a.length() && a.charAt(ai) != '.') { ++ai; } ++ai; // Skip the dot. int bn = 0; while (bi < b.length() && b.charAt(bi) != '.') { ++bi; } ++bi; // Skip the dot. if (cmp != 0) return cmp; } if (ai < a.length()) return 1; if (bi < b.length()) return -1; return 0; } List<String> lines = new ArrayList<>(); String line; while ((line = reader.readLine()) != null) { lines.add(line); } } lines.sort(Ideone::compare); } }
1 1.1 1.1.1 2 2.1 9 9.1 9.9 10 10.1
Shuffled: [9, 2, 1.1, 1.1.1, 9.1, 9.9, 1, 2.1, 10.1, 10] Sorted: [1, 1.1, 1.1.1, 2, 2.1, 9, 9.1, 9.9, 10, 10.1]