Good day. Can you please tell me how to sort String's using Comparable? It is clear when you work with a primitive of type Int. But how to do it with a thong? Thank.
1 answer
List<String> list = new ArrayList<String>(); // дальше добавляем строки в list [...] // сама сортировка list.sort((String o1, String o2)->o1.compareTo(o2)); Without lambda:
Collections.sort(list, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); |