Without generics it is possible to create an ArrayList
with elements of different types. I want to iterate through it and put out the elements. I can not use a for-each-loop, because it wants a specific type. I tried Iterator
but wasn't successful.
So I have two questions:
Is it possible to iterate through an array list and put out (e. g. with
System.out.println
) all elements no matter of which type they are?Is it possible to iterate through an array list and put out only the elements which are of a specific type (e. g. only the Strings)?