One, for each underlying implementation
For the collection,for each is implicitly called iterator implementation, the efficiency is slightly lower than the display call iterator, for the array,for each is achieved by the subscript reference, the efficiency is lower than the for loop. For Each returns a collection object, so you cannot use for each to assign a value.
Second, the collection implements the iterator interface, so the list, Queue, and set can all be traversed using the for each method.
Three, hashmap three kinds of traverse way:
①map.entryset () returns a set<entry<k,v>>, and then uses for each (implicitly calls iterator)
map<string, string> map = new hashmap<string, string> (); for (entry<string, string> Entry:map.entrySet ()) { entry.getkey (); Entry.getvalue ();}
②map.keyset () returns a Set<key>, and then uses for each (implicitly calls iterator)
map<string, string> map = new hashmap<string, string> (); for (String Key:map.keySet ()) {map.get (key);}
③map.value () returns a Collection<value>, and then uses for each (implicitly calls iterator)
Array goto List
String[] Strarray = {"AAA", "BBB", "CCC"};
List list= arrays.aslist (Strarray);
Note that list is ArrayList type, but it is not the same as java.util.ArrayList. Strarray must be an object array, and if it is a primitive type array, List.size () is 1,
Collection to Array
Direct use of the collection ToArray () method
Map Turn Collection
Use the values () method of the map directly.
List and set conversions
A collection object can be passed directly through the constructor function.
Reference: http://www.cnblogs.com/xwdreamer/archive/2012/05/30/2526822.html
Collection, MAP, array traversal mode