fork(1) download
  1. import java.util.*;
  2.  
  3. class Test {
  4.  
  5. public static void main(String[] args) {
  6. List<Integer> a = Arrays.asList(1);
  7. List<Integer> b = Arrays.asList(1,2);
  8. List<Integer> c = Arrays.asList(1,2,3);
  9. List<Integer> d = Arrays.asList(1,2,3,4);
  10.  
  11. List<List<Integer>> test = Arrays.asList(d,b,c,a);
  12. Collections.sort(test, ListSizeComparator.INSTANCE);
  13. for (List<Integer> list : test) {
  14. System.out.println(list.size());
  15. }
  16. }
  17.  
  18. enum ListSizeComparator implements Comparator<List> {
  19. INSTANCE;
  20.  
  21. public int compare(List one, List other) {
  22. return one.size() - other.size();
  23. }
  24. }
  25. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
1
2
3
4