adding a key to HashMap without the value?

前端 未结 5 2236
孤城傲影
孤城傲影 2021-02-19 14:37

Is there a way to add a key to a HashMap without also adding a value? I know it seems strange, but I have a HashMap> amd I wan

5条回答
  •  被撕碎了的回忆
    2021-02-19 15:10

    Yes, it was confusing enough ;) I don't get why you want to store keys without values instead just putting empty arraylists instead of null.

    Adding null may be a problem, because if you call

    map.get("somekey");
    

    and receive a null, then you do not know, if the key is not found or if it is present but maps to null...

提交回复
热议问题