I have list and list of lists:
ArrayList<String> singleList = new ArrayList<String>();
ArrayList<ArrayList<String>> listOfLists = new ArrayList<ArrayList<String>>();
I do not understand the behavior of these lists. I decided to show you a simple example:
listOfLists.clear();
singleList.clear();
singleList.add("A");
singleList.add("B");
singleList.add("C");
listOfLists.add(singleList);
singleList.clear();
singleList.add("D");
singleList.add("E");
singleList.add("F");
listOfLists.add(singleList);
singleList.clear();
singleList.add("G");
singleList.add("H");
singleList.add("I");
listOfLists.add(singleList);
for(int x = 0; x < listOfLists.size(); x++)
{
for(int z = 0; z < singleList.size(); z++)
{
System.out.print(listOfLists.get(x).get(z));
System.out.print(" ");
}
System.out.println("");
}
And the result I got was:
G H I G H I G H I
Instead:
A B C D E F G H I
Where is a problem with my thinking? What should I do to get result as above?