adding a key to HashMap without the value?

前端 未结 5 2233
孤城傲影
孤城傲影 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:02

    I'm not sure you want to do this. You can store null as a value for a key, but if you do how will be able to tell, when you do a .get("key") whether the key exists or if it does exist but with a null value? Anyway, see the docs.

提交回复
热议问题