Java Basic Problems

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(“\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());




1 thought on “Java HashMap Key Value Pair: How to show the Key Value pair data of HashMap.”

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



Leave a Reply

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

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

Facebook photo

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

Connecting to %s