top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: What are different Collection views provided by Map interface?

+1 vote
667 views
Java: What are different Collection views provided by Map interface?
posted Mar 14, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Map is object which maps keys to its values. Map can’t contain duplicate keys. Each key will map to one value. Map interface includes methods which can be used for general operations i.e.get, put, containsKey, containsValue, remove, size, and empty for bulk operations i.e. putAll and clear.

It provides three collection views methods which allow Map to be viewed as Collection in below ways:

Keyset: This method provides Set of the keys contained in Map.
entrySet: This method provides Collection of values contained in Map. Please note basically this Collection is not Set because we can have multiple keys that is map to same value.
Values: This method provides Set of key value pairs contained in Map. Map interface provides small nested interface that is called Map.Entry and type of the elements in this Set.

answer Mar 16, 2016 by Shubham Singh
...