View RSS Feed

Hashmap

Hashmap in Java

  1. Java's SortedMap Interface

    by , 02-19-2012 at 07:38 AM
    The java.util.Map interface’s subtype is the java.util.SortedMap. Functionality of java.util.Map is extended by this interface and elements are sorted which have been stored in the Map, internally.

    Element’s sorting orders are as following:

    • If java.lang.Comparable is implemented then it means that there exist element’s natural sorting order.
    • Comparator determines the order which you will be providing to the SortedSet.


    Default sorting orders are ascending ...
    Categories
    Hashmap
  2. Removing Elements from Map

    by , 02-19-2012 at 07:36 AM
    From Map, the removal of elements is done by using remove (Object key) method. This would be removing pair (Key, Value) from Map.

    Any type of elements could be put into Map. Type of objects can be limited to be used for values or keys in a Map. How to limit values or keys is well explained in the given code.
    Java Code: This is the code to limit values or keys
    Map<String, MyObject> map = new HashSet<String, MyObject>();
    Map just accepts the value son MyObject type or keys of string type, ...
    Categories
    Hashmap
  3. Adding and Accessing Map Elements

    by , 02-19-2012 at 07:24 AM
    For addition of elements to Map, use put() method. This process is explained by the given code.
    Java Code: This is the code to explain map add operation
    Map mapA = new HashMap();
    mapA.put("key1", "element 1");
    mapA.put("key2", "element 2");
    mapA.put("key3", "element 3");
    Key values are mapped by calling 3 put() methods, in the code given above. Both values & keys are String, in above code. To get value, use this code.
    Java Code: This is the code to explain map access operation
    String
    ...
    Categories
    Hashmap
  4. Java Map Implementations

    by , 02-19-2012 at 07:21 AM
    Map can’t be instantiated as it is an interface. For creation of the Map interface instance, concrete implementation is required. Map interface has these concrete implementations which are present in Collection API.

    • java.util.HashMap
    • java.util.Hashtable
    • java.util.EnumMap
    • java.util.IdentityHashMap
    • java.util.LinkedHashMap
    • java.util.Properties
    • java.util.TreeMap
    • java.util.WeakHashMap

    Map implementations which ...
    Categories
    Hashmap
  5. Java Hash Map

    by , 02-19-2012 at 07:19 AM
    Key value paired data structure is provided by the Map interface so that for mapping the keys to values. Keys are unique which are used for retrieval of the values, from Map.

    Key features are as following:

    • Key value repair is used for storage of all values. Key is used for the retrieval.
    • When Map doesn’t contain any element, various methods throw the “NoSuchElementException”.
    • When compatibility of element is not present with map elements, ClassCastException gets
    ...
    Tags: hash map Add / Edit Tags
    Categories
    Hashmap