Map as our common container, in the study and work with a lot of, the following describes several ways to traverse the Map collection object for your reference
The first, in the For-each loop, uses the entry object to traverse each key-value pair in the map, a method that is more commonly used, However, For-each is introduced after java1.5, so it requires a version above 1.5 to be used, and for a foe-each traversal of an empty map throws a null pointer exception, you need to be aware that the map is empty
The second, similar to the first one, is also a for-each loop, but the object of the loop is a key or a value, and the notation is similar
The third type, using an iterator to traverse, puts an example
Of course, in addition to the entry object that can iterate map, but also can iterate the key or value, here is not introduced, this method has the iterator traversal container of a bit, the operation is rich, the use of the history is relatively long, performance is also very advantageous
This is a few commonly used and good performance of the traversal method, the next time you can compare their performance.
Java Traversal Map Object