在java中的map中查找更大的数字

时间:2017-09-23 10:30:57

标签: java

HashMap<String, Map<Integer, Integer>> outer = new HashMap<>();
String abc = //someString;
maxNumber = //somevalue;
minNumber = //somevalue;
Map<Integer,Integer> inner = new HashMap<>();
inner.put(minNumber, maxNumber);
outer.put(abc, inner);

有类似下面的代码。我正从内部地图中检索更多的数字,尝试但无法获取。

for (Map.Entry<String, Map<Integer, Integer>> outer1 : outer.entrySet()) {
    System.out.println("Feature: " + outer1.getKey() +  "\n");
    for (Map.Entry<Integer, Integer> entry : outer1.getValue().entrySet()) {
   //.... stuck here.
}

如何从内部地图中获得更大的价值?

1 个答案:

答案 0 :(得分:0)

minNumber是内部地图的关键。因此值为maxNumber

for (Map.Entry<String, Map<Integer, Integer>> outer1 : outer.entrySet()) {
    System.out.println("Feature: " + outer1.getKey() +  "\n");
    for (Map.Entry<Integer, Integer> entry : outer1.getValue().entrySet()) {
        Integer key = entry.getKey(); // == minNumber
        Integer value = entry.getValue(); // == maxNumber
}