HashMap存储自定义类型键值
Map集合保证key是唯一的:
作为key的元素,必须重写hashCode方法和equals方法,以保证key唯一
- HashMap存储自定义类型键值
key:Person类型,Person类必须重写hashCode方法和equals方法,以保证key唯一
value:String类型,value可以重复(同名同年龄的人视为同一个)
private static void show1() {
//创建HashMap集合
HashMap<Person,String> map=new HashMap<>();
map.put(new Person("张三",18),"北京");
map.put(new Person("李四",