bc0026c3e1
Plus many new examples in "streams" chapter.
17 lines
404 B
Java
17 lines
404 B
Java
// containers/ForInCollections.java
|
|
// All collections work with for-in.
|
|
import java.util.*;
|
|
|
|
public class ForInCollections {
|
|
public static void main(String[] args) {
|
|
Collection<String> cs = new LinkedList<>();
|
|
Collections.addAll(cs,
|
|
"Take the long way home".split(" "));
|
|
for(String s : cs)
|
|
System.out.print("'" + s + "' ");
|
|
}
|
|
}
|
|
/* Output:
|
|
'Take' 'the' 'long' 'way' 'home'
|
|
*/
|