Does LinkedHashMap returns linked Set?
Method keySet()
.
Exa开发者_运维问答mples works fine, but I not sure if I'm right.
Looking at the JDK1.5 source, it seems that the keyset returned from LinkedHashMap
defines an iterator whose ordering is consistent with that of the map.
However, since this isn't documented anywhere, I'd treat the behaviour as an implementation detail, and wouldn't rely on it in my code.
LinkedHashMap
inherets keySet()
from HashMap
:
https://docs.oracle.com/javase/1.5.0/docs/api/java/util/LinkedHashMap.html#methods_inherited_from_class_java.util.HashMap
keySet()
returns an object of class Set
:
https://docs.oracle.com/javase/1.5.0/docs/api/java/util/HashMap.html#keySet%28%29
精彩评论