get string value from HashMap depending on key name

前端 未结 10 2009
误落风尘
误落风尘 2020-11-28 21:39

I have a HashMap with various keys and values, how can I get one value out?

I have a key in the map called my_code, it should contain a str

10条回答
  •  無奈伤痛
    2020-11-28 22:07

    If you are storing keys/values as strings, then this will work:

    HashMap newMap = new HashMap();
    newMap.put("my_code", "shhh_secret");
    String value = newMap.get("my_code");
    

    The question is what gets populated in the HashMap (key & value)

提交回复
热议问题