简体   繁体   中英

Java Map get value from key

i want to get value from key using following code.

 for (Entry<Integer, String> entryName : MainActivity.list1) {                      
 if (entry.getKey() == (entryName.getKey()))
 }

How can I get value if my entryName Map has key using entryName.getkey() ?

    Map<String,String> myMap = new HashMap<String,String>();     
    myMap.put("Assembly", "One");       
    myMap.put("Prliament", "Two");      

    Integer key=2;
     for(Map.Entry entry: map.entrySet()){
        if(key == entry.getKey()){
           System.out.println(entry.getValue());
        break; 
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM