View RSS Feed

Algorithm and Data Structure

Algorithm and data structure examples in Java.

  1. 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