09 April 2012

Create a Hash Map to store the Asia Pacific countries and their capitals. Display the capital based on the country name.




package one;

import java.util.*;


public class One {

public static void main(String[] arr) {

/* Create object of HashMap */

HashMap<String, String> obHashMap = new HashMap<String, String>();

/* Store value in HashMap */

obHashMap.put("Bhutan", "Thimphu ");

obHashMap.put("China", "Beijing ");

obHashMap.put("India", "New Delhi ");

obHashMap.put("Israel", "Jerusalem ");

obHashMap.put("Japan", "Tokyo ");

/* Create a set of keys of hashmap */
System.out.print("COUNTRY"+ ": ");
System.out.println("CAPITAL");
Set set=obHashMap.entrySet();
Iterator obIter = set.iterator();

while (obIter.hasNext()) {
Map.Entry me=(Map.Entry)obIter.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}

 }

}

2 comments:

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

akhila priya said...

This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up Java online training

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;