Java Set foreach Example
Set
Set<String> colourSet = new HashSet<>();
colourSet.add("RED");
colourSet.add("GREEN");
colourSet.add("BLUE");
colourSet.add("YELLOW");
colourSet.add("BLACK");
colourSet.add("WHITE");
for (String color : colourSet){
System.out.println( color);
}
Java 8 Lambdas
colourSet.forEach(color -> System.out.println(color));
Reference
https://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html
No comments:
Post a Comment