需要一些帮助:我不熟悉 HashMap 。如何将列表和数组与 HashMap 进行比较?列表和数组保存整数。
map :
Map<Integer, String> profMap = new HashMap<Integer, String>() {};
while(profs.next()){
Integer key= profs.getInt("profid");
String name= profs.getString("profname");
profMap.put(key,name);
}
/* profs comes from my sql statement and pulls values from those columns*/
数组:
String [] profArray = request.getParameterValues("professor");
列表:
List list= new ArrayList();
我迷失在文档和我见过的所有其他示例中。希望有人能帮我解决这个问题
最佳答案
根据您的评论,您希望比较键并存储与匹配的键关联的值。
你可以做到这一点。
foreach(Integer key in profMap.keyset()) {
if(/* Check the key against your criteria */) {
list.add(ProfMap.get(key));
}
}
关于java - 比较 Hashmap 和 List list = new Arraylist(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9577836/