T
Todor Atanasov
Hi,
I am very new to the JAVA, but I have some experience in programming, like C++/MFC and php.
I have a question regarding List, and more precisely a specific case which I fail to get the logic.
This is the example code:
List groups = new ArrayList();
List group = null;
for(int i = 0; i < 20; i++{
TestClass test = new TestClass();
if(group == null || flag)){
group = new ArrayList();
groups.add(group);
}
...... //the flag is set on some condition
group.add(test);
}
I get the first nationalization of the group list with new ArrayList, but isn't every single group list after that, when the flag is set, also initialized, resulting in a empty group, which are then added to the groups??
I am very new to the JAVA, but I have some experience in programming, like C++/MFC and php.
I have a question regarding List, and more precisely a specific case which I fail to get the logic.
This is the example code:
List groups = new ArrayList();
List group = null;
for(int i = 0; i < 20; i++{
TestClass test = new TestClass();
if(group == null || flag)){
group = new ArrayList();
groups.add(group);
}
...... //the flag is set on some condition
group.add(test);
}
I get the first nationalization of the group list with new ArrayList, but isn't every single group list after that, when the flag is set, also initialized, resulting in a empty group, which are then added to the groups??