Java Stream

example

String[] arr = new String[]{"Hello", "World", "Hell"};
Stream<String> stream = Arrays.stream(arr); // 전체 배열
Stream<String> streamOfArrayPart = Arrays.stream(arr, 1, 3); // 부분 배열
List<String> list = Arrays.asList("a", "b", "c");
Stream<String> stream = list.stream();
Stream<String> parallelStream = list.parallelStream(); // 병렬 처리 스트림
Path path = Paths.get("/path/to/testfile.txt");
Stream<String> streamOfStrings = Files.lines(path);
Stream<String> streamWithCharset = Files.lines(path, Charset.forName("UTF-8"));
Stream<Object> stream = Stream.empty();
Stream<String> streamEmpty = Stream.empty();
Stream<String> generatedStream = Stream.<String>builder()
    .add("Hello")
    .add("World")
    .build();
Stream<String> strStream = Arrays.asList("Hello", "World", "Java").stream();
int sum = strStream.parallel()
    .mapToInt(s -> s.length())
    .sum();

ref

What Else?
inflearn react api server -50% 할인쿠폰: 15108-f2af1e086101 buy me a coffee