View RSS Feed

My Java Tips

HashMap - useful methods

Rate this Entry
by , 11-01-2011 at 06:24 PM (920 Views)
I will present few important methods of HashMap class in this post.

The most useful methods are: get and put.

get(Object key) returns the value associated with specified key. It returns null if there is no value for this key.
put(K key, V value) associates the specified value with the specified key.

Other useful methods are:

containsKey(Object key) - (boolean) returns true if this map contains a value for the specified key
values() - returns a collection of the values contained in this map
keySet() - returns a set view of the keys contained in this map
remove(Object key) - removes the mapping for key from this map if present
isEmpty() - (boolean) returns true if this map contains no key-value mappings

Submit "HashMap - useful methods" to Facebook Submit "HashMap - useful methods" to Digg Submit "HashMap - useful methods" to Submit "HashMap - useful methods" to StumbleUpon Submit "HashMap - useful methods" to Google

Tags: None Add / Edit Tags
Java SE