Java-验证hashmap中的键是否存在于另一个hashmap中



如何验证hashmap中的键是否存在于其他hashmap中。

我有两个标签图

tablePlayer: <"Kim":"1" , "Bot":"2" , "Tim":"3">
tempPlayerList: <"Kim":"4" , "Bob":"1">

我的想法是使用tempPlayerList密钥来查找是否有具有相同值的密钥,例如,Kim应该是true,Bob应该是false

有办法做到这一点吗?

我真的不明白你想要什么,但你可以做:

for(String playerName : tablePlayer.keySet()){
if(tempPlayerList.containsKey(playerName)){
//hasmap contain name
}else{
//hasmap do not contain name
}
}

最新更新