Daftar Sortir 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
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> list= new ArrayList<>();
list.add("Apple");
list.add("Mango");
list.add("Banana");
System.out.println("List : "+list);
//will sort the string acc to the alphabets
Collections.sort(list);
System.out.println("Sorted List : "+list);
}
}
Collections.sort(testList);
Collections.reverse(testList);
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());
}
}