先看api:
Class HashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
Type Parameters:
K - the
type of keys maintained by this
map
V - the
type of mapped values
All Implemented Interfaces:
Serializable, Cloneable,
Map<K,V>
Direct Known Subclasses:
LinkedHashMap, PrinterStateReasons
!!敲黑板!! 一定要注意,HashMap 是泛型类(class),它实现了Map接口。 请不要实例化接口!
HashMap<String,String> t=
new map<String,String>();
HashMap t=
new map<String,String>();
正确写法:
HashMap
map =
new HashMap<
Integer,
String>();
ps:终于会设置markdown的颜色了!