So I have a TreeMap TreeMap<Integer, String> map = new TreeMap<>();
and lets say that it only contains this: mapa.put(i, "first");
(i = 0)
now I want to iterate and add elements to map but for some reason it will iterate just once although I have added more elements in for loop
for(Map.Entry<Integer, String> entry: mapa.entrySet()){
mapa.put(i+1, ""+i);
System.out.println(entry);
if(i == 10){
break;
}
i++;
}
it will write out just this:
0=first
How can I iterate through map that can change size in for loop?
Thank you!