Example
Retrieve all the values from a map.
import java.util.HashMap;
public class Main {
public static void main(String[] args ) {
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities .put("England", "London");
capitalCities .put("Germany", "Berlin");
capitalCities .put("Norway", "Oslo");
capitalCities .put("USA", "Washington DC");
System.out .println(capitalCities .values());
}
}
|
Definition and Usage
The values() method returns a collection of all the values in the map.
Note: This collection is a view of the map, so changes to the collection reflect in the map.
Syntax
public Collection<V> values()
|
V denotes the data type of the values in the map.
Technical Details
Returns:
|
A collection that includes all the values in the map.
|