What is AbstractMap values() in Java?

The values()method

The values() method of the AbstractMap class gets the Collections view of the values stored in the map.

Syntax

public Collection<V> values()

Parameters

This method has no parameters.

Return value

This method returns a collection view of the values in the map.

Example

import java.util.*;
public class Main{
public static void main(String[] args) {
AbstractMap<String, String> abstractMap = new HashMap<>();
abstractMap.put("hello-1", "Educative");
abstractMap.put("hello-2", "edpresso");
abstractMap.put("hello-3", "answers");
System.out.println(abstractMap.values());
}
}

Explanation

  • Line 5: We define an abstract map. The abstract map has the implementation of the hash map.
  • Lines 6–8: We use the put() method to add entries to the map.
  • Line 9: We invoke the values() method to obtain the values of the map. We then print these values.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved