定义一个员工类
public class Employee {private String name;private String ags;public void setName(String name) {this.name = name;}public String getName() {return name;}public void setAgs(String ags) {this.ags = ags;}public String getAgs() {return ags;}
}
定义测试类
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;//map中泛型的使用
public class test74 {public static void main(String[] args){Map<String, Set<Employee>> map=new HashMap<String,Set<Employee>>();//创建员工对象Employee emp0=new Employee();emp0.setName("李小龙");Employee emp1=new Employee();emp1.setName("梁小龙");Set<Employee> empSet=new HashSet<>();empSet.add(emp0);empSet.add(emp1);map.put("emps",empSet);Set<Employee> empSet2=map.get("emps");for(Employee emp:empSet2){System.out.println(emp.getName());}}
}
运行结果