Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 2, 2001

How to Use Maps Effectively


The java.util.Map interface is the root interface of the map hierarchy. Interestingly, it doesn't extend the familiar java.util.Collection interface. It facilitates storage, retrieval, and manipulation of key-value pairs.

The popular implementations of Map are java.util.HashMap and java.util.TreeMap. The HashMap facilitates easy insertion, deletion, and retrieval of elements. On the other hand, TreeMap is a neat alternative to traverse the keys of a map in a sorted order.
 
// MapDemo.java

import java.util.*;

/** Demonstrates the use of popular java.util.Map implementations. */
public class MapDemo {

  /** The hash map to add data. */
  private HashMap hashMap;
  /** The tree map to sort data. */
  private TreeMap treeMap;

  /** Starts the demo. */
  public void startDemo() {

    // Initialize the hash map
    hashMap = new HashMap();
    hashMap.put(
Shantanu Garg
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date