Map接口_简单应用
public class TestMap2 {
public static void main(String[] args) {
Employee e1 = new Employee(1001,"阿狸",50000);
Employee e2 = new Employee(1002,"阿卡丽",50000);
Employee e3= new Employee(1003,"波比",50000);
Map <Integer,Employee> map = new HashMap<>();
map.put(1001, e1);
map.put(1002, e2);
map.put(1003, e3);
Employee emp = map.get(1001);
System.out.println(emp.name);
}
}
class Employee{
int num;
String name;
int salary;
public Employee(int num, String name, int salary) {
super();
this.num = num;
this.name = name;
this.salary = salary;
}
}
效果