Java 8 Streams
Java
224
java8
10
stream
11
Male avatar

loveprogramming viết ngày 18/04/2021

https://grokonez.com/java/java-8/java-8-streams

Java 8 Streams

Java 8 comes with some prominent features like Lambda Expressions, Method References. And Streams are also an important concept that we should comprehend.

This tutorial will help you have a deep view of Java 8 Streams: what they are, ways to create them, how they work with intermediate operations, terminal operation...

I. Overview

1. What is Java 8 Stream?

A stream is an abstract concept that represents a sequence of objects created by a source, it’s neither a data structure nor a collection object where we can store items. So we can't point to any location in the stream, we just interact with items by specifying the functions.

This is an example of a Stream:


List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
// get List from Stream Operation
List result = numbers.stream()
        .filter(i -> (i % 2) == 0)
        .map(i -> "[" + i + "]")
        .collect(Collectors.toList());

System.out.println(result);

Run the code above, the console shows:


[[2], [4], [6], [8]]

Now, we have concept of using a Stream is to enable functional-style operations on streams of elements. Those operations are composed into a stream pipeline which consists of:
Source > Intermediate Operations > Terminal Operation

  • a source (in the example, it is a collection - List, but it is also an array, a generator function, an I/O channel...)
  • intermediate operations (which transform current stream into another stream at the current chain, in the example, filter is the first operation and map is the second one)
  • a terminal operation (which produces a result or side-effect, in the example, it is collect)

More at:

https://grokonez.com/java/java-8/java-8-streams

Java 8 Streams

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

545 bài viết.
98 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết hơn 1 năm trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết hơn 1 năm trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết hơn 1 năm trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/java/java8/howtousejava8streamcollectorsgroupingbyexamples How to use Java 8 Stream Collectors.groupingBy() Examples no_toc]...
loveprogramming viết 1 năm trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
545 bài viết.
98 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!