Java HashMap class

Java HashMap class implements the map interface by using a hashtable. It inherits AbstractMap class and implements Map interface.

The important points about Java HashMap class are:

  • A HashMap contains values based on the key.
  • It contains only unique elements.
  • It may have one null key and multiple null values.
  • HashMap class declaration

    public class HashMap extends AbstractMap implements Map, Cloneable, Serializable

    Constructors

    HashMap() It is used to construct a default HashMap.

    HashMap(Map m) It is used to initializes the hash map by using the elements of the given Map object m.

    HashMap(int capacity) It is used to initializes the capacity of the hash map to the given integer value, capacity.

    Method

    void clear() It is used to remove all of the mappings from this map.

    boolean containsKey(Object key) It is used to return true if this map contains a mapping for the specified key.

    boolean containsValue(Object value) It is used to return true if this map maps one or more keys to the specified value.

    boolean isEmpty() It is used to return true if this map contains no key-value mappings.

    Object clone() It is used to return a shallow copy of this HashMap instance: the keys and values themselves are not cloned.

    Set keySet() It is used to return a set view of the keys contained in this map.

    EXAMPLE

    Flash Soon



    Advertisement

    Copyright ©2017 Design& develop