我有一张 map HashMap <Integer,Employee> map= new HashMap<Integer,Employee>();
类(class)Employee
有一个 int 属性 int empid;
它将作为 map 的关键。
我的方法是
public Set<Employee> listAllEmployees()
{
return map.values(); //This returns a collection,I need a set
}
如何通过该方法获取一组员工?
最佳答案
只需使用 map.values()
创建一个新的 HashSet
public Set<Employee> listAllEmployees()
{
return new HashSet<Employee>(map.values());
}
关于java - 从 map 返回一组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19075027/