This is kinda working:
ArrayList<Object> list1 = new ArrayList<>();
list1.add("Hello");
list1.add(1.5);
list1.add(new Whatever());
ArrayList<ArrayList<Object>> listAll = new ArrayList<>();
listAll.add(list1);
In an ArrayList of Object you can add any Object... also you can add the same ArrayList with Objects into another ArrayList of Object. Why is this not working:
ArrayList<String> list1 = new ArrayList<>();
list1.add("Hello");
list1.add(new String("World!"));
ArrayList<ArrayList<Object>> listAll = new ArrayList<>();
listAll.add(list1);
I have an ArrayList of Strings (String is an Object) and I cannot add these although these are Objects in listAll
.
PS: JDK1.7
Edit: Well I do read this 'duplicate', about Dogs and Cats. Not sure I got it, but alright :)