我最近一直在学习HashMaps,但我有一个问题似乎无法得到明确的答案。两者的主要区别是-
HashMap hash1 = new HashMap();vs
HashMap<,>hash1 = new HashMap <,> (); //Filled in with whatever Key and Value you want. 我认为当你定义一个HashMap时,它需要键和值。任何帮助都将不胜感激。谢谢。
发布于 2012-10-31 02:09:48
以下是您拥有的选项:
J2SE <5.0样式:
Map map = new HashMap();J2SE 5.0+样式(使用generics):
Map<KeyType, ValueType> map = new HashMap<KeyType, ValueType>();Google Guava样式(更短、更灵活):
Map<KeyType, ValueType> map = Maps.newHashMap();https://stackoverflow.com/questions/13144685
复制相似问题