我有一Person
堂课:
public class Person{
private String name;
//pleaese think this 'id' simply as an attribute of Person, same as e.g. age, height
private long id;
public Person(String name, long id){
this.name = name;
this.id = id;
}
public String getName(){
return name;
}
public long getId(){
return id;
}
}
然后,我有一个HashMap
实例,其中包含Person
从服务器获取的多个 s:
//key is String type, it is a unique name-like string assigned to each Person
//value is a Person object.
HashMap<String, Person> personsMap = GET_PERSONS_FROM_SERVER();
然后,我有一组人员 ID:
long[] ids = new long[]{1,2,3,4,5, …}
我需要的是生成另一个 HashMap
只包含 id 列在ids
数组中的人员:
// Only the person whose id is listed in ids array will be in the following Map
Map<String, Person> personNeeded = … ;
如何以personNeeded
有效的方式获得?