hashmap的嵌套,存储一个自定义类
/*
* hashmap的嵌套,存储一个自定义类
*
*分析:
* 1.创建一个hashmap,且它的键和值的其中一个也是hashmap
* 2.创建两个hashmap,它的键 是自定义类Student
* 3.创建Student对象,并分别向第二步的两个hashmap添加
* 4.分两种方法遍历输出
*/
自定义类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
hashmap类:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
输出结果:
Student [name=李四, age=2]=2
Student [name=王二, age=4]=4
Student [name=赵大, age=3]=3
Student [name=张三, age=1]=1
-------------------------------------------------
Student [name=李四, age=2]
Student [name=王二, age=4]
Student [name=赵大, age=3]
Student [name=张三, age=1]