java - 比较 Hashmap 和 List list = new Arraylist()

标签 java arrays list hashmap

需要一些帮助:我不熟悉 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/

相关文章:

list - 如何避免R中的循环:从列表中选择项目

java - 如何从 logback 配置对象中记录

java - JBOSS 主目录不存在

php - 将多个文件上传到 mySQL 然后添加到 Session

Sharepoint Lists.asmx : The request failed with an empty response

python - 为什么使用列表时用 numba 计算总和会变慢?

java - 使用 xstream 自定义 java 集合的序列化

java - 如何告诉java泛型类型是函数式接口(interface)?

c# - 推送索引数组

java - 在两个数组中查找重复值