私はハッシュマップを作成しました。キーの文字列と値としてのオブジェクトを含んでいます。ただし、値の一部を取得しようとすると、nullの結果が返されます。Java HashMapは、一部のキーでnull値を返します。 。 。時々
// This returns all the keys and their values.
for (String key : DevicesUsed.devicesUsedMap.keySet()) {
if(DevicesUsed.devicesUsedMap.containsKey(key)) {
System.out.println(key + " exists");
System.out.println(key + "\t" + DevicesUsed.devicesUsedMap.get(key));
} else {
System.out.println("Key does not exist.");
}
}
// This only works for some of the keys, that worked in the above code.
System.out.println(DevicesUsed.devicesUsedMap.get("WHITEALL")); // Works.
System.out.println(DevicesUsed.devicesUsedMap.get("REDCOVE")); // Returns null.
screen shot of the console output
キーのいくつかは、一つのブロックではなく、他に存在する理由として非常に混乱して。
昨日または今朝この同じ質問をしていませんでしたか? –
これをデバッガで実行すると、どのような情報が得られますか?そして、まだエラーを分離しようとするテストプログラム、[mcve]を作成しましたか?もしそうなら、投稿してください。そうでない場合は、作成を検討してください。 –
@ J-Alexキーは 'String'のように見えるので、そうではありません。 – chrylis