import java.util.HashMap; import java.util.Map; public class MapValuesExample { public static void main(String[] args) { MapIn this example, we create a HashMap and add key-value pairs. Then we use the values() method to get the collection of values and print them to the console. The java.util Map values belong to the java.util package library.map = new HashMap<>(); map.put("John", 25); map.put("Lily", 30); map.put("Sam", 28); map.put("Tom", 32); // Get the collection of values System.out.println("Values in the map are: " + map.values()); } }