在Java中引用两个变量

时间:2016-07-21 19:22:28

标签: java arrays json

假设我有三个ArrayList和一个HashMap,如下所示:

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<>();

我做了:

m.put(0, C);//setting values to the hashmap
C.clear();//resetting value of C

但这也清除了C内部m哈希映射,导致m = [0, ""]。为什么这是Java的情况?

我期待的是这个

int A = 1;
int B = 2;
int C = A+B //result is 3

现在,如果我设置A=0,则不应影响C

的最终值

有人可以向我解释一下吗?

0 个答案:

没有答案