[Solved] Take only the first hashmap value [closed]


Try this.

public static void main(String[] args) {
    HashMap<String, Object> map = new HashMap<>();
    map.put("one", "壱");
    map.put("two", "弐");
    map.put("three", "参");
    map.put("four", "四");

    System.out.println("hash map = " + map);

    Object firstValue = map.values().iterator().next();

    System.out.println("first value = " + firstValue);
}

output:

hash map = {four=四, one=壱, two=弐, three=参}
first value = 四

solved Take only the first hashmap value [closed]