i've seen the answer of How do HashMap.values() and HashMap.keySet() return values and keys? and Java: private inner class synthesized constructors i think this question is not duplicate...
i still don't know how keySet() of HashMap works the point confused me is: it's null before call the method keySet(),but once invoked,the value "keySet" will be associated with the map.
Map map = new HashMap();
map.put(1, 1); //null
map.keySet(); //[1]
map.put(2, 2); //[1,2]
map.remove(2); //[1]
so i'm strange about how it works....
the inner class KeySet can access the Outter class "HashMap" variables,but in class AbstractMap,there is only a Set keySet = null;,the keys and values are stored in the Entry[] table; together, i still cant find a method like
for(Entry e : table) {
keySet.put(e.getKey());
}
to make a refer between only map keys and keySet