Java HashMap Key Value Pair: How to show the Key Value pair data of HashMap.

hashmap key value pair data javaSometimes in java while we do coding and use HashMap we may need to check or see the values reside in Key and their corresponding Data or Values at the same time. Here I am sharing you another simple but useful technique to see the key value pair data of HashMap at a time. Just copy the code below and run it on your computer.

Here is the code:

import java.util.HashMap;

public class HashMap1

  {

  public static void main( String[] args )

    {

    HashMap map = new HashMap();

    map.put(new Integer(10), “Jhony” );

    map.put(new Integer(11), “Tom” );

    map.put(new Integer(12), “Tom” );

    System.out.println(“\n****************************************”);

    System.out.println(“\nKey Value Pair of HashMap 1st Way :”+map);

    System.out.println(“\nKey Used in HashMap :”+map.keySet());

    System.out.println(“\nKey Value Pair of HasMap in 2nd Way :”+map.entrySet());

    System.out.println(“\nValue Used in HashMap :”+map.values());

    System.out.println(“\n****************************************”);

    }

  }

About these ads

One Response to Java HashMap Key Value Pair: How to show the Key Value pair data of HashMap.

  1. javarevisited says:

    Hi,
    Thanks for htis Nice artilce just to add while discussing about HashMap its worth mentioning following questions which frequently asked in Java interviews now days like How HashMap works in Java or How get() method of HashMap works in JAVA very often. on concept point of view these questions are great and expose the candidate if doesn’t know deep details.

    Javin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 312 other followers