Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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();
Shantanu Garg
Comment and Contribute






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



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