Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较HashMap<;字符串,ArrayList<;字符串>&燃气轮机;和ArrayList<;字符串>;JAVA_Java_Jsp_Servlets_Netbeans_Hashmap - Fatal编程技术网

比较HashMap<;字符串,ArrayList<;字符串>&燃气轮机;和ArrayList<;字符串>;JAVA

比较HashMap<;字符串,ArrayList<;字符串>&燃气轮机;和ArrayList<;字符串>;JAVA,java,jsp,servlets,netbeans,hashmap,Java,Jsp,Servlets,Netbeans,Hashmap,我有一个HashMap,其中包含一个单词列表Map 还有一个包含单词的列表,我想将这个列表与另一个包含二进制值的HashMap进行比较 如果单词存在,则为1;如果单词不存在,则为0。 代码是 HashMap hmm=new HashMap(); System.out.println(“附件列表:”); 对于(条目ee:hm.entrySet()){ String key=ee.getKey(); 列表值=ee.getValue(); 用于(字符串临时:列表) hmm.add(values.con

我有一个
HashMap
,其中包含一个单词列表
Map
还有一个包含单词的列表,我想将这个列表与另一个包含二进制值的
HashMap
进行比较 如果单词存在,则为1;如果单词不存在,则为0。 代码是

HashMap hmm=new
HashMap();
System.out.println(“附件列表:”);
对于(条目ee:hm.entrySet()){
String key=ee.getKey();
列表值=ee.getValue();
用于(字符串临时:列表)
hmm.add(values.contains(temp)?“1”:“0”);
}

您可以比较如下代码:

  List<String> global = new ArrayList<String>;
    Map<String,  ArrayList<String>> newMap = new HashMap<String, ArrayList<String>>();
    Map<String,  ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
    for (String key:map.keySet()) {
        List<String> arrayList= map.get(key);
        for (String words:arrayList) {
            List<String> newList = new ArrayList<String>;
            for (String globallist:global) {
                if(words.equals(globallist)){
                    newList.add(words);
                }
            }
            newMap.put(key,newList);
        }
    }
List global=new ArrayList;
Map newMap=newhashmap();
Map Map=newhashmap();
for(字符串键:map.keySet()){
List arrayList=map.get(key);
for(字符串:arrayList){
List newList=newarraylist;
for(字符串全局列表:全局){
if(单词等于(全球列表)){
添加(单词);
}
}
newMap.put(key,newList);
}
}

根据您的帮助,我找到了这个解决方案,非常感谢 根据你的帮助,我找到了这个解决方案,非常感谢

             HashMap<String,ArrayList<String>> hmm=new            
             HashMap<String,ArrayList<String>>();  
             for (Entry<String, List<String>> ee : hm.entrySet()) {
             String key = ee.getKey();

             List<String> values = ee.getValue();
             List<String> list5=new ArrayList<String>();
             for (String temp : global){

             list5.add(values.contains(temp) ? "1" : "0");


               } 
                hmm.put(key, (ArrayList<String>) list5);




             }'
HashMap hmm=new
HashMap();
对于(条目ee:hm.entrySet()){
String key=ee.getKey();
列表值=ee.getValue();
List list5=新的ArrayList();
用于(字符串温度:全局){
列表5.add(values.contains(temp)-“1”:“0”);
} 
hmm.put(key,(ArrayList)list5);
}'

请以文本形式而不是图像形式发布您的代码。请参见下面我的答案。我不理解将
地图
列表
进行比较背后的过程-很明显,它们之间从来都不相等。那是地图钥匙吗?什么是地图值?列表中是什么?什么是成功比较?什么不是?请详细说明你的问题,它的当前形式对我来说没有任何意义。@M.Prokhrov这里有一个例子,全局列表[“a”,“b”,“c”]hashmap[1][“a”,“c”][2][“a”,“b”][3][“a”,“b”,“c”],我想要一个包含新hashmap[1][“1”,“0”,“1”][2][“1”,“1”,“0”][3][“1”,“1”,“1”]谢谢,但我想将全局列表中的值与hashmap中的值进行比较,并将rsult(o,1)放入新的hashmap中
             HashMap<String,ArrayList<String>> hmm=new            
             HashMap<String,ArrayList<String>>();  
             for (Entry<String, List<String>> ee : hm.entrySet()) {
             String key = ee.getKey();

             List<String> values = ee.getValue();
             List<String> list5=new ArrayList<String>();
             for (String temp : global){

             list5.add(values.contains(temp) ? "1" : "0");


               } 
                hmm.put(key, (ArrayList<String>) list5);




             }'