The map interfaces 

Because the map intc·rt.lCes define of maps begins with them, The  interfaces tlr pcrt  Each interface is examined next, in turn.

The Map Interlace

The Map interface maps unique keys to values. A key is an object that you use to retrieve a value at a later date: Given a' key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key. The methods declared by Map are summarized in Table 15-6. Several methods throw a NoSuchElementException when no items exist in the invoking map. A ClassCastException is thrown when an object is incompatible with the dements in <1 map. A NullPointerException is thrown if an attempt is made to List a null object and null is nut allowed in the map. An UnsupportedOperationException is thrown when an attempt is made to change <An Unmodifiable map. Maps revolve around two basic operations: get( ) and put( ). To put a value into a map, use put(), specifying the key and the 'value. To obtain a value, call get(), passing the key as an argument. The value is returned. As mentioned earlier, maps are not collections, but you·can obtain a collection-view of a map. To do this, you can use the entl'}'Set( ) method. It returns a Set that contains the elements in the map. To obtain a collection-view of tho keys, collection-view of the values, use values] ). Collection-views are the means by which maps are integrated into the collections framework.

Share This