How do you iterate in Hashmap?

Answer Posted / varun

HashMap<String, String> loans = new HashMap<String, String>();
loans.put("home loan", "citibank");
loans.put("personal loan", "Wells Fargo");

for (String key : loans.keySet()) {
System.out.println("------------------------------------------------");
System.out.println("Iterating or looping map using java5 foreach loop");
System.out.println("key: " + key + " value: " + loans.get(key));
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What modifiers may be used with an interface declaration?

558


What is JTS?

1862


What are JTA/JTS and how they used by client?

1716


When a thread blocks on i/o, what state does it enter?

572


What is a sessionfactory? Is it a thread-safe object?

679






Describe, in general, how java's garbage collector works?

536


What state does a thread enter when it terminates its processing?

600


For which statements does it make sense to use a label?

585


What class is the top of the awt event hierarchy?

576


which type of objects reference will be given to client?

2027


What is clustering? What are the different algorithms used for clustering?

576


Where can I ask questions and make suggestions about seam?

588


What is in-memory replication?

557


What is ioc concept & explain it?

618


What is the difference between the ‘font’ and ‘fontmetrics’ class?

636