[JAVA rookie] ask questions about keySet

questions are as follows:

clipboard.png

clipboard.png

clipboard.png

I encountered this problem when I was doing a problem, but I didn"t understand it.

Collection c = m2.keySet();

in this line of code in the title, the keySet on the right is a Set, taken out of the Map. First of all, the Map should not be unordered, the Set taken out is also unordered, and finally put in the Collection is also unordered. How is it that the last iteration is in order? How did this order come out?

Aug.31,2021

TreeMap is ordered Map

Menu