开发者

Retrieving objects from a HashMap using java

Suppose开发者_运维百科 that you have:

Map<something of enum type, Object>;

If you know the enum, how do you gain access to the ObjecT?


For enums it works the same way as for maps in general:

Object value = map.get(enumKey);

Note that with enum keys, it is recommended to use an EnumMap instead of HashMap.


Use get:

Object result = map.get(key);


http://download.oracle.com/javase/tutorial/java/javaOO/enum.html

Enums are objects in java. As such, they can be used as keys in the get method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜