Commit 4b3a87c5 authored by Trisha Gee's avatar Trisha Gee
Browse files

Examples for foreach

parent 2c2822a4
Loading
Loading
Loading
Loading
+15 −0
Changes for src/main/java/Ch10c.java: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
import java.util.List;

public class Ch10c {
    void forExample() {
        List<String> allColors = List.of("Red", "Blue", "Yellow");
        for (String color : allColors) {

            System.out.println(color);
        }
    }
    void forEachExample() {
        List<String> allColors = List.of("Red", "Blue", "Yellow");
        allColors.forEach(color -> System.out.println(color));
    }
}