COPY/*** HashMap的使用* 存储结构:哈希表(数组+链表+红黑树)*/public class Demo2 {public static void main(String[] args) {HashMap<Student, String> hashMap=new HashMap<Student, String>();Student s1=new Student("tang", 36);Student s2=new Student("yu", 101);Student s3=new Student("he", 10);//1.添加元素hashMap.put(s1, "成都");hashMap.put(s2, "杭州");hashMap.put(s3, "郑州");//添加失败,但会更新值hashMap.put(s3,"上海");//添加成功,不过两个属性一模一样;//注:假如相同属性便认为是同一个对象,怎么修改?hashMap.put(new Student("he", 10),"上海");System.out.println(hashMap.toString());//2.删除元素hashMap.remove(s3);System.out.println(hashMap.toString());//3.遍历//3.1 使用keySet()遍历for (Student key : hashMap.keySet()) {System.out.println(key+" "+hashMap.get(key));}//3.2 使用entrySet()遍历for (Entry<Student, String> entry : hashMap.entrySet()) {System.out.println(entry.getKey()+" "+entry.getValue());}//4.判断//注:同上System.out.println(hashMap.containsKey(new Student("he", 10)));System.out.println(hashMap.containsValue("成都"));}}