[Solved] printing an array with arbitrary nesting levels, in java [closed]


You can do this recursivly by checking if the current element is again a list and by using the toString-method which every object in java has.

public void printList(List<Object> a)
{
    for (Iterator<Object> it = a.iterator(); it.hasNext();) {
        Object item = it.next();
        if (item instanceof List) printList((List<Object>) item);
        else System.out.print(item + ", ");
    }
}

solved printing an array with arbitrary nesting levels, in java [closed]