Java Hashmap values() Method

hashmap-values-method

Java Methods

Methods are used to preform a specific task. Methods are reusable in nature. Instead of writing the code again you can use method to perform that specific task. In Java there are two types of methods, ‘user defined’ and ‘built-in’ methods. User-defined methods are declared by the programmer according to their needs while built-in methods are pre defined methods which make programming easy. The Hashmap class in java also have some inbuilt methods. One of those methods is the Java Hashmap values() Method.

To know more about Hashmap values() Method read the complete article

Java Hashmap values() Method

The hashmap values() method is used to check the values  mapped in the hashmap . This method returns the  values which are mapped to the key in the hashmap. Below in this page you can find it’s syntax, return values, parameters with detailed examples.

Syntax :

hashmap.values();

Return values :

Collection view of values mapped to the keys in the hashmap. 
Java-hashmap-values-method

Hashmap replace() Method Examples

Example :

Run
import java.util.*;
public class Main
{
  public static void main (String[]args)
  {

    // Creating an empty HashMap
    HashMap < Integer, String > hash_map_1 =
      new HashMap < Integer, String > ();


    // Mapping string values to int keys in a empty hashmap
    hash_map_1.put (10, "Java");
    hash_map_1.put (20, "Hashmap");
    hash_map_1.put (25, "Values");
    hash_map_1.put (30, "Method");

    //printig the values mapped in hashmap
    System.out.println ("values mapped in the hashmap :  " +
			hash_map_1.values ());


  }
}

Output :

values mapped in the hashmap :  [Hashmap, Values, Java, Method]

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription