import java.util.HashMap;
import java.util.Map;
class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
public class Demo2 {
public static void main(String[] args) {
Map<Integer, Person> map = new HashMap<>();
map.put(1, new Person("张三", 23));
map.put(2, new Person("张二", 25));
map.put(3, new Person("张一", 21));
System.out.println(map);
System.out.println(map.get(3).getName());
}
}