我已经将 hashmap 转换为 json,因为我不知道 java 中的 itt 是什么样的
所以我的 HashMap 看起来像
{"1":[true,false],
"2":[true,true],
"3":[true]}
我需要在单个键中获取数组列表中所有 true 的第一次出现
在本例中,它的 2 是第一次出现
所以如果发生了///做其他事情//做其他事情
hm.forEach((key, value) -> {
for (Object object : value) {
boolean b = (boolean)object;
if(!b){
break;
}else{
System.out.println(key+"->"+b);
}
}
});
我尝试过类似的方法,但我在其中迷失了方向,它对所有情况进行了测试
任何帮助将不胜感激
最佳答案
尝试下面的代码片段。
hm.forEach((key, value) -> {
boolean allTrue=true;
for (Object object : value) {
allTrue = (boolean)object;
if(!allTrue){ //stop if you found a false in the true/false array
break;
}
}//out of the inner iteration
if(allTrue){//if this variable is true, it means the above iteration had all values true
//do your stuff
break;
}
allTrue=true; //reset
});
关于java - 如何过滤 HashMap 并找到第一次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47261110/