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

Which javutil classes and interfaces support event handling?

776


What is Stream Tokenizer?

1939


What is the diffrence between a local-tx-datasource and a xa-datasource? Can you use transactions in both?

760


Difference between swing and awt?

811


What is the relationship between the canvas class and the graphics class?

744






Explain phantom read?

1946


Explain what is orm?

844


Can I use javascript to submit a form?

842


What is the difference between session and entity beans?

784


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

800


Can we sent objects using Sockets?

838


What must a class do to implement an interface?

750


difference between  ejb,struts,hibernate,spring and jsp

2550


What is bean? Where can it be used?

781


Are we allowed to change the transaction isolation property in middle of a transaction?

758