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
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.