Search a value for a given key in a HashMap

前端 未结 4 1094
余生分开走
余生分开走 2021-02-05 06:51

How do you search for a key in a HashMap? In this program, when the user enters a key the code should arrange to search the hashmap for the corresponding value and

4条回答
  •  梦毁少年i
    2021-02-05 07:49

    Just call get:

    HashMap map = new HashMap();
    map.put("x", "y");
    
    String value = map.get("x"); // value = "y"
    

提交回复
热议问题