没有问题.请看下面的例子://MapDemo.java
public class MapDemo {
public static void main(String args[]) {
java.util.Map map = new java.util.HashMap();
// push to map
for (int i=0; i<10; i++) {
Character c = new Character((char)('0' + i));
map.put(c, String.valueOf(i));
}
// find in map
for (int i=0; i<10; i++) {
Character c = new Character((char)('0' + i));
Object o = map.get(c);
if (o == null)
System.out.println("not found the value of " + c + ".");
else {
System.out.println("key:" + c + " value:" + o);
}
}
}
}
public class MapDemo {
public static void main(String args[]) {
java.util.Map map = new java.util.HashMap();
// push to map
for (int i=0; i<10; i++) {
Character c = new Character((char)('0' + i));
map.put(c, String.valueOf(i));
}
// find in map
for (int i=0; i<10; i++) {
Character c = new Character((char)('0' + i));
Object o = map.get(c);
if (o == null)
System.out.println("not found the value of " + c + ".");
else {
System.out.println("key:" + c + " value:" + o);
}
}
}
}
在hashMap中是会用到你写的类的hashCode的。effictive java这本书中有介绍!
还有hashCode 必须遵循一致性,自反性等等一些原则
具体的你可以去java的官方网站看看