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 if the static modifier is removed from the signature of the main method?

709


Explain about RMI Architecture?

612


Can you give me a simple example of using the requiredif validator rule?

608


Why a client should be multithreading? Explain.

597


What is the difference between ear, jar and war file?

576






What is the RMI and Socket?

627


Which container method is used to cause a container to be laid out and redisplayed?

671


Can I map more than one table in a cmp?

593


In RMI, inorder to sent the stub reference to the client, is we have to load the server object first into the memory or can we directly sent reference to the client?

1564


What are the benefits of detached objects?

587


What is a tasks priority and how is it used in scheduling?

552


Why doesn’t the focus feature on the tag work in every circumstance?

573


Why use a datasource when you can directly specify a connection details?

534


What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

589


What does module-relative mean?

581