Search code examples
javaarraylisttostringpretty-print

How to print an ArrayList of ArrayLists so that each inner list is printed on one row?


I have an ArrayList of ArrayLists - something like ArrayList<ArrayList<Node>>. Since I get this as a return value from a function, after every call a different size is called. I am wondering how to display its elements is such a way that the inner ArrayList constitutes one row and so for every row.

What would be my required parameter(s) for the for loop? Thanks in advance.


Solution

  • for (List<Node> l1 : arrayLists) {
       for (Node n : l1) {
           System.out.print(n + " "); 
       }
    
       System.out.println();
    }