I am using java
public class MapsConfusion {
public static void main(String[] args) {
HashMap< Integer, ArrayList<String>> map = new HashMap<>();
for (int i = 0; i < 15; i++){
ArrayList<String> lst = new ArrayList<>();
lst.add("something");
lst.add("something2");
map.put(i, lst);
}
for(int j = 0; j < 11; j++){
System.out.println(map.get(j));
}
}
}
How it works, every time it goes around it, it creates an arrayalist new . Here is my question
When thinking of pointers , when you declare a new Arraylist<>one each time, you create a new one Arraylist at a new address, will I fix it?
Another question . The list does not exist only within scope, that is for loop?. Then how else is available when I do another (last) for the loop?
source
share