get string value from HashMap depending on key name

前端 未结 10 2024
误落风尘
误落风尘 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:04

    If you will use Generics and define your map as

    Map map = new HashMap();
    

    then fetching value as

     String s = map.get("keyStr"); 
    

    you wont be required to typecast the map.get() or call toString method to get String value

提交回复
热议问题