简体   繁体   English

从 LinkedHashMap 获取所有值,其中 key = x

[英]Get all values from LinkedHashMap where key = x

I have a LinkedHashMap.我有一个 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());

      }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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