Skip to content Skip to sidebar Skip to footer

How To Get Hashmap Values Depends On Key

i have this hashmap with string and arraylis: Map> devNameType = new HashMap>(); public void kimenetPV(S

Solution 1:

You can print the key:value pairs as this:

Iterator<Entry<String, List<String>>> iter = devNameType.entrySet().iterator();
while (iter.hasNext()) {
    Entry<String, List<String>> next = iter.next();
    List<String> value = next.getValue();
    System.out.println("key = " + next.getKey());
    System.out.println("values : ");
    for (String str : value) {
        System.out.println(str);
    }
}

Solution 2:

With hashMap.values() you get a Collection of all values: http://developer.android.com/reference/java/util/HashMap.html#values()

Post a Comment for "How To Get Hashmap Values Depends On Key"