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());
}
}
}
Program output:
as in the code above, when arrStr changes, so does mm. How do you make arrStr change while mm remains the same?