Search a value for a given key in a HashMap

前端 未结 4 1092
余生分开走
余生分开走 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条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 07:33

    //If you want the key to be integer then you will have to declare the hashmap //as below :

    HashMap map = new HashMap();
    map.put(0, "x");
    map.put(1, "y");
    map.put(2, "z");
    

    //input a integer value x

    String value = map.get(x);
    

提交回复
热议问题