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 are the oops concept?

571


How a component can be placed on Windows?

2257


How is a java object message delivered to a non-java client?

569


what are getters and setters in Java with examples?

1278


To what value is a variable of the string type automatically initialized?

600






Can you control when passivation occurs?

591


What is Remote Server?

1679


Can I use javascript to submit a form?

603


Brief description about local interfaces?

618


Explain phantom read?

1732


What are the call back methods in entity bean?

551


What is table mutation and how do you avoid it?

1908


How would you create a button with rounded edges?

551


Which javutil classes and interfaces support event handling?

572


Why are my checkboxes not being set from on to off?

630