HashMap values() Method in Java Last Updated : 26 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The java.util.HashMap.values() method of HashMap class in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the HashMap. Syntax: Hash_Map.values() Parameters: The method does not accept any parameters. Return Value: The method is used to return a collection view containing all the values of the map. Below programs are used to illustrate the working of java.util.HashMap.values() Method: Program 1: Mapping String Values to Integer Keys. Java // Java code to illustrate the values() method import java.util.*; public class Hash_Map_Demo { public static void main(String[] args) { // Creating an empty HashMap HashMap<Integer, String> hash_map = new HashMap<Integer, String>(); // Mapping string values to int keys hash_map.put(10, "Geeks"); hash_map.put(15, "4"); hash_map.put(20, "Geeks"); hash_map.put(25, "Welcomes"); hash_map.put(30, "You"); // Displaying the HashMap System.out.println("Initial Mappings are: " + hash_map); // Using values() to get the set view of values System.out.println("The collection is: " + hash_map.values()); } } Output: Initial Mappings are: {20=Geeks, 25=Welcomes, 10=Geeks, 30=You, 15=4} The collection is: [Geeks, Welcomes, Geeks, You, 4] Program 2: Mapping Integer Values to String Keys. Java // Java code to illustrate the values() method import java.util.*; public class Hash_Map_Demo { public static void main(String[] args) { // Creating an empty HashMap HashMap<String, Integer> hash_map = new HashMap<String, Integer>(); // Mapping int values to string keys hash_map.put("Geeks", 10); hash_map.put("4", 15); hash_map.put("Geeks", 20); hash_map.put("Welcomes", 25); hash_map.put("You", 30); // Displaying the HashMap System.out.println("Initial Mappings are: " + hash_map); // Using values() to get the set view of values System.out.println("The collection is: " + hash_map.values()); } } Output: Initial Mappings are: {4=15, Geeks=20, You=30, Welcomes=25} The collection is: [15, 20, 30, 25] Note: The same operation can be performed with any type of Mappings with variation and combination of different data types. Comment More infoAdvertise with us Next Article HashMap values() Method in Java chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-HashMap +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads IdentityHashMap values() Method in Java The java.util.IdentityHashMap.values() method of IdentityHashMap class in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the Map. Syntax: Identity_Hash_Map.values() Parameters: The method does not accept any parameters. Retur 2 min read HashMap size() Method in Java The size() method of the Java HashMap class is used to retrieve the number of key-value pairs currently stored in the HashMap.Example 1: This example demonstrates the use of the size() method to get the number of elements in the HashMap.Java// Java program to demonstrates the working of size() impor 2 min read Java HashMap put() Method The put() method of the Java HashMap class is used to add or update the key-value pairs in the map. If the key already exists in the map, the previous value associated with the key is replaced by the new value and If the key does not exist, the new key-value pair is added to the map.Syntax of HashMa 1 min read HashMap clear() Method in Java The clear() method of the HashMap class in Java is used to remove all of the elements or mappings (key-value pairs) from a specified HashMap.Example 2: Here, we will use the clear() method to clear a HashMap of Integer keys and String values. Java// Clearing HashMap of Integer keys // and String val 2 min read IdentityHashMap put() Method in Java The java.util.IdentityHashMap.put() method of IdentityHashMap is used to insert a mapping into a map. This means we can insert a specific key and the value it is mapping, into a particular map. If an existing key is passed then the previous value gets replaced by the new value. If a new pair is pass 3 min read Set hashCode() Method in Java In Java, the hashCode() method is defined in the Object class and is used to generate a hash code for objects. It plays a very important role in hash-based collections like HashMap, HashSet, and HashTable. Example 1: This example demonstrates how hashCode() is used to get the hash code of the HashSe 2 min read Vector hashCode() Method in Java The java.util.vector.hashCode() method in Java is used to get the hashcode value of this vector. Syntax: Vector.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Vector which is of Integer type. Below programs illustrate the Java. 2 min read HashMap compute() Method in Java The compute(Key, BiFunction) method of the HashMap class in Java is used to update or compute a value for a specific key. It tries to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). If the remapping function passed to compute() returns n 4 min read Map Values() Method in Java With Examples Map Values() method returns the Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. Syntax: map.values() Parameter: This method does not take any parameter. Return value: It returns a collect 2 min read HashMap entrySet() Method in Java The entrySet() method of the HashMap class in Java is used to create a set view of the mappings contained in the HashMap. This method allows us to iterate over the key-value pairs in the map or convert them into a set.Example 1: Here, we will use the entrySet() method to view the mappings in a HashM 2 min read Like