Список сортировки Java
List<String> entries = new ArrayList<>();
entries = entries.stream().sorted().collect(Collectors.toList());
Adorable Addax
List<String> entries = new ArrayList<>();
entries = entries.stream().sorted().collect(Collectors.toList());
List<String> list = new ArrayList<>();
java.util.Collections.sort(list); // sorts lexicographically
Collections.sort(al);
class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> {
@Override
public int compare(List<T> o1, List<T> o2) {
for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) {
int c = o1.get(i).compareTo(o2.get(i));
if (c != 0) {
return c;
}
}
return Integer.compare(o1.size(), o2.size());
}
}
List<String> elements = new ArrayList<>();
// The list of strings will be sorted lexicographically
elements.sort();
// You can also implement a custom comparator
Comparator<String> comp = new Comparator<String>(){
@Override
public int compare(final String s1,String s2) {
//TODO return 1 if rhs should be before lhs
// return -1 if lhs should be before rhs
// return 0 otherwise (meaning the order stays the same)
}
};
elements.sort(comp);