23.11.2017 Views

java_tutorial

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java<br />

boolean isEmpty( )<br />

3<br />

Returns true if the dictionary is empty, and returns false if it contains at least<br />

one key.<br />

4<br />

Enumeration keys( )<br />

Returns an enumeration of the keys contained in the dictionary.<br />

Object put(Object key, Object value)<br />

5<br />

Inserts a key and its value into the dictionary. Returns null if the key is not<br />

already in the dictionary; returns the previous value associated with the key if<br />

the key is already in the dictionary.<br />

6 Object remove(Object key)<br />

Removes the key and its value. Returns the value associated with the key. If<br />

the key is not in the dictionary, a null is returned.<br />

7 int size( )<br />

Returns the number of entries in the dictionary.<br />

The Dictionary class is obsolete. You should implement the Map interface to obtain<br />

key/value storage functionality.<br />

The Map Interface<br />

The Map interface maps unique keys to values. A key is an object that you use to retrieve<br />

a value at a later date.<br />

<br />

<br />

<br />

<br />

<br />

Given a key and a value, you can store the value in a Map object. After the value<br />

is stored, you can retrieve it by using its key.<br />

Several methods throw a NoSuchElementException when no items exist in the<br />

invoking map.<br />

A ClassCastException is thrown when an object is incompatible with the elements<br />

in a map.<br />

A NullPointerException is thrown if an attempt is made to use a null object and null<br />

is not allowed in the map.<br />

An UnsupportedOperationException is thrown when an attempt is made to change<br />

an unmodifiable map.<br />

359

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!