HashMap
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));
}
Set
Iterator
while (keySetIterator.hasNext()) {
System.out.println("------------------------------------------------");
System.out.println("Iterating Map in Java using KeySet Iterator");
String key = keySetIterator.next();
System.out.println("key: " + key + " value: " + loans.get(key));
}
Set
for (Entry entry : entrySet) {
System.out.println("------------------------------------------------");
System.out.println("looping HashMap in Java using EntrySet and java5 for loop");
System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());
}
Set
Iterator
while (entrySetIterator.hasNext()) {
System.out.println("------------------------------------------------");
System.out.println("Iterating HashMap in Java using EntrySet and Java iterator");
Entry entry = entrySetIterator.next();
System.out.println("key: " + entry.getKey() + " value: " + entry.getValue());
}
No comments:
Post a Comment