How to traverse the map collection using an iterator

        Since the iterator cannot be instantiated directly in the map collection, the following provides a method of using the iterator in the map collection.

            1. Although the iterator cannot be directly instantiated in the map, the map collection provides the keySet() method and the value() method, which can be conscious of the list collection or map collection by first outputting the key value to a collection.

            2. The iterator can be instantiated directly through the set of keys.

            3. During the iterative operation, you can use the get() method to find out the value corresponding to each key and output it.


            code show as below:

                Map mm=new HashMap();
Set keySet = mm.keySet();
Iterator iterator=keySet.iterator();
while(iterator.hasNext()) {
Object key = iterator.next();
Object value = mm.get(key);
System.out.println(key+"   "+value);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324707867&siteId=291194637