Java HashMap.values()

Syntax

HashMap.values() has the following syntax.

public Collection <V> values()

Example

In the following code shows how to use HashMap.values() method.


//  ww w.j a v  a2  s  .  c  o m
import java.util.HashMap;

public class Main {
   public static void main(String args[]) {

      HashMap<Integer, String> newmap = new HashMap<Integer, String>();      
      
      // populate hash map
      newmap.put(1, "tutorials");
      newmap.put(2, "from");
      newmap.put(3, "java2s.com");
      
      System.out.println(newmap.values());
   }    
}

The code above generates the following result.