public class ListMap {
HashMap<Integer, List> mp = new HashMap();
List myList = new ArrayList();
Integer x = 0;
Integer y = 5;
void test() {
for(Integer i = 0; i < 5; i++) {
x = y;
myList.add("check-1a" + i);
myList.add("check-1a" + i + 1);
y = null;
System.out.println(x); // output=5
mp.put(i, myList);
myList.clear();
}
}
1) But after clearing the List with myList.clear() the values that was inside the Map also gets cleared.
I mean to say that the map key remains there but it contains an "empty" List
2) However regarding the Objects x & y, after setting y to null how come x doesn't change?
ListandArrayList.HashMap<Integer, List<String>>,List<String>, andArrayList<String>.