import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Map; public class Reminder { public static void main(String args[]) { ArrayList<String> arrStr = new ArrayList<>(); Map<String,ArrayList<String>> mm = new HashMap<String, ArrayList<String>>(); arrStr.add("12"); arrStr.add("23"); mm.put("1",arrStr); Iterator<Map.Entry<String, ArrayList<String>>> at = mm.entrySet().iterator(); while (at.hasNext()){ Map.Entry<String, ArrayList<String>> entry=at.next(); System.err.println(entry.getValue()); } arrStr.set(1,"222"); Iterator<Map.Entry<String, ArrayList<String>>> at2 = mm.entrySet().iterator(); while (at2.hasNext()){ Map.Entry<String, ArrayList<String>> entry=at2.next(); System.err.println(entry.getValue()); } } }
程序输出:
如上代码,当arrStr改变的时候,mm也跟着改变了。怎么才能让arrStr更改的同时,mm不变呢?
德玛西亚99
相关分类