I'm facing the problem and I did not find for any exact explanation for it. I am running the program in debug mode, I see that when the variable add to g_temNodes arraylist: g_tempNodes.add(p_dept_cd); , that variable also automatically add to g_nodes before the running g_nodes.add(g_tempNodes); .
Pls give me some ways to solve it. Thanks in advance.
my code is as the followings.
ArrayList<ArrayList<String>> g_nodes = new ArrayList<ArrayList<String>>();
ArrayList<String> g_tempNodes = new ArrayList<String>();
...
...
private String GetDeptCd(String x_dept_cd, int x_flag) {
...
...
while (p_sql.next()) {
String p_dept_cd = p_sql.getString("dept_cd");
if(x_flag == 0){
g_tempNodes.removeAll(g_tempNodes);
}
g_tempNodes.add(p_dept_cd);
System.out.println("g_tempNodes = "+g_tempNodes);
g_nodes.add(g_tempNodes);
System.out.println("g_nodes = "+g_nodes);
GetDeptCd(p_dept_cd, 1);
g_tempNodes.remove(g_tempNodes.size()-1);
}
return null;
}
This is the output in console.
g_tempNodes = [100]
g_nodes = [[100]]
g_tempNodes = [100, 999]
g_nodes = [[100, 999], [100, 999]]
g_tempNodes = [100, 101]
g_nodes = [[100, 101], [100, 101], [100, 101]]