简体   繁体   中英

Get all values from LinkedHashMap where key = x

I have a LinkedHashMap. How can I get all the values where the key is equal to what the user select?

To get the value of a 'Key' you just need to iterate through the entry set. Not sure if this is what you want - but as comments suggest you're quite vague with what you actually want. Post some code for a better answer!

 Map<String, String> map = new LinkedHashMap<String,String>();

    map.put("one", "value 1");
    map.put("two", "value 2");
    map.put("three", "value 3");

    for (Map.Entry<String,String> entry : map.entrySet()){

      if (entry.getKey().equals("two")){

        System.out.println(entry.getValue());

      }

    }

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