-1
我试图使用contains方法来传递整数-1来检查valuesset Hashmap。尽管此值存在于valueset中,但它返回null。我的地图是(字符串,整数)格式,但通过调试看我可以看到-1在地图存储为长(我试图检查包含Long.valueof(-1)这也是错误的)。Map.containsValue返回False,尽管指定的值存在于valueset中,并且没有任何对象类型不匹配
我试图使用contains方法来传递整数-1来检查valuesset Hashmap。尽管此值存在于valueset中,但它返回null。我的地图是(字符串,整数)格式,但通过调试看我可以看到-1在地图存储为长(我试图检查包含Long.valueof(-1)这也是错误的)。Map.containsValue返回False,尽管指定的值存在于valueset中,并且没有任何对象类型不匹配
假设你的情况我尝试以下,但它的工作对我来说:
public static void mapContainsIssue() {
// create hash map
HashMap<String, Integer> newmap = new HashMap<>();
// populate hash map
newmap.put("tutorials", 23);
newmap.put("point", -1);
newmap.put("is best", 2);
// check existence of value 'point'
System.out.println("Check if value '-1' exists: "
+ newmap.containsValue(-1));
}
以及我的问题只有此修复返回true if(req_wat_user.relationship.values()。toString()。contains(“ - 1”)) – amar
你怎么知道'dataSnapshot2'实际上包含任何数据?您的屏幕截图不显示此检查。你可以编辑你的问题,并包括代码? –
查看截图中调试器的第3行.. dataSnapshot2上有值 – amar
为什么在Map中存在Long值? –
4castle