String[] getContainsValue = { strHi, strHello, strThere };
for (int x = 0; x < getContainsValue.length; x++) {
getContainsValue[x] = containsValue[x]; // 只修改數組元素,不影響 strHi 等變量
}
Java 為**值傳遞**,數組存儲的是字符串引用的副本,修改數組元素**不會**回寫到原變量。
Map map = new HashMap<>();
map.put("strHi", "hi");
map.put("strHello", "hello");
map.put("strThere", "there");
String value = map.get("strHello"); // 獲取 "hello"
map.put("strHello", "new value"); // 修改映射值
僅能「讀取」數組元素賦值給變量:
strHi = containsValue[0];
strHello = containsValue[1];
strThere = containsValue[2];
但無法實現「修改數組自動同步變量」的雙向綁定。