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. public static void main (String[] args) throws java.lang.Exception {
  10. ArrayList<List<Integer>> group = new ArrayList<List<Integer>>();
  11. group.add(Arrays.asList(1, 2, 3));
  12. group.add(Arrays.asList(4, 5, 6));
  13. group.add(Arrays.asList(7, 8, 9));
  14.  
  15. // Uncomment the below line and you'll see that it won't work
  16. // group.get(1).add(2342);
  17.  
  18. for (List<Integer> list : group) {
  19. for (Integer i : list) {
  20. System.out.print(i+" ");
  21. }
  22. System.out.println();
  23. }
  24. }
  25. }
Success #stdin #stdout 0.13s 50460KB
stdin
Standard input is empty
stdout
1 2 3 
4 5 6 
7 8 9