Created
September 11, 2019 14:03
-
-
Save JHarry444/71a3ff01f06bdeb422d7ddab6dbdfe66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| import java.util.stream.IntStream; | |
| public class StreamExample { | |
| public static void main(String[] args) { | |
| List<Integer> list = new ArrayList<>(); | |
| IntStream.range(0, 10).forEach(list::add); | |
| // list.stream().filter(i -> i % 2 == 0).forEach(i -> System.out.println(i)); | |
| // list.stream().map(i -> i * i).forEach(i -> System.out.println(i)); | |
| // System.out.println(list.stream().reduce((accumulator, next) -> Math.max(accumulator, next)).get()); | |
| list = list.stream().map(i -> i + i).collect(Collectors.toList()); | |
| System.out.println(list); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment