LinkedHashMap values() in Java

values(): This method is available in java.util.LinkedHashMap class of Java.

Syntax:

Collection<V> java.util.LinkedHashMap.values()

This method returns a Collection view of the values contained in this map.

Parameters: NA

Returns: a view of the values contained in this map.

Exceptions: NA

Approach

Java

import java.util.LinkedHashMap;

public class LinkedHashMapvalues {

    public static void main(String args[]) {

        LinkedHashMap<String, Integer> linkedHashMap =
new LinkedHashMap<String, Integer>();

        linkedHashMap.put("Java", 1);
        linkedHashMap.put("Hello", 2);

        System.out.println(linkedHashMap.values());

    }

}

Output:

[1, 2]


No comments:

Post a Comment