Let's say I have three ArrayList and a HashMap as follows:
public HashMap<Integer, ArrayList<String>> m = new HashMap<>();
public ArrayList<JSONObject> A = new ArrayList<>();
public ArrayList<JSONArray> B = new ArrayList<>();
public ArrayList<String> C = new ArrayList<>();
And I do:
m.put(0, C);//setting values to the hashmap
C.clear();//resetting value of C
But this also clear the C inside m hashmap, resulting m = [0, ""]. Why is this the case in Java?
What I was expecting is this
int A = 1;
int B = 2;
int C = A+B //result is 3
Now if i set A=0 this shouldn't affect the final value of C
Can someone please explain this to me?