java.util.HashMap.values() Method


Description

The values() method is used to return a Collection view of the values contained in this map.

Declaration

Following is the declaration for java.util.HashMap.values() method.

public Collection<V> values()

Parameters

NA

Return Value

The method call returns a collection view of the values contained in this map.

Exception

NA

Example

The following example shows the usage of java.util.HashMap.values()

package com.tutorialspoint;

import java.util.*;

public class HashMapDemo {
   public static void main(String args[]) {
      
      // create hash map
      HashMap newmap = new HashMap();      

      // populate hash map
      newmap.put(1, "tutorials");
      newmap.put(2, "point");
      newmap.put(3, "is best");

      // checking collection view of the map
      System.out.println("Collection view is: "+ newmap.values());
   }    
}

Let us compile and run the above program, this will produce the following result.

Collection view is: [tutorials, point, is best]
java_util_hashmap.htm
Advertisements