HashMap Iteration
Here is one way of getting the values from a map without using the method get(Object key)
import java.util.*;
public class HashTest {
public static void main(String[] args) {
HashMap map = new HashMap();
map.put("name1", "abc");
map.put("name2", "xyz");
map.put("name3", "mno");
map.put("name4", "123");
map.put("name5", "567");
Collection collection = map.values();
Iterator its = collection.iterator();
while(its.hasNext()) {
System.out.println("Result: " + its.next() );
}
}
}
0 Comments:
Post a Comment
<< Home