OnJava8-Examples/containers/ForInCollections.java
Bruce Eckel bc0026c3e1 Radically reorganized
Plus many new examples in "streams" chapter.
2015-11-11 20:20:04 -08:00

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'
*/