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.
Parameter: This method does not take any parameter.
Return value: It returns a collection view of all the values present in the map.
[student 4, student 3, student 6, student 1, student 2, student 5]
As you can see, the output of the above example is returning a collection view of values. So any change in the map will be reflected in the collection view automatically. So always take the generic of collection same as the generic of the values of the map otherwise it will give an error.
<------OutPut before modification------> student 4 student 3 student 6 student 1 student 2 student 5 <------OutPut after modification------> student 4 student 3 student 6 student 1 student 2 student 7 student 5