fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<List<Integer>> outer=new ArrayList<>();
  13. // fill outer
  14. List<Integer> tmpList = new ArrayList<>();
  15. tmpList.add(1);
  16. outer.add(tmpList);
  17. tmpList = new ArrayList<>();
  18. tmpList.add(1); tmpList.add(2);
  19. outer.add(tmpList);
  20. tmpList = new ArrayList<>();
  21. tmpList.add(1); tmpList.add(2); tmpList.add(3);
  22. outer.add(tmpList);
  23. System.out.println(outer);
  24.  
  25.  
  26. int maxColSize = outer.stream().mapToInt(List::size).max().orElse(0);
  27. for (int y=0; y<maxColSize; y++) {
  28. for (int x=0; x<outer.size(); x++) {
  29. List<Integer> currentInner = outer.get(x);
  30. if (currentInner.size() > y) {
  31. System.out.println(currentInner.get(y));
  32. }
  33. }
  34. }
  35. }
  36. }
Success #stdin #stdout 0.19s 320832KB
stdin
Standard input is empty
stdout
[[1], [1, 2], [1, 2, 3]]
1
1
1
2
2
3