From 57d59d5a77954897731464940e7444836d3ed316 Mon Sep 17 00:00:00 2001 From: "Anh N. Nguyen" Date: Tue, 16 Oct 2018 07:57:27 +0700 Subject: [PATCH] Update java lambda expression guilde (#19102) --- .../guide/english/java/lambda-expressions/index.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/pages/guide/english/java/lambda-expressions/index.md b/client/src/pages/guide/english/java/lambda-expressions/index.md index b73e402e75..91acd964b6 100644 --- a/client/src/pages/guide/english/java/lambda-expressions/index.md +++ b/client/src/pages/guide/english/java/lambda-expressions/index.md @@ -14,7 +14,7 @@ The Stream Api is used in java to allow chaining of sequential and aggregate ope In this small example you can see that one of the utilities of a stream is to receive a certain property of all objects in a list and return it in another list using intermediate and terminal operations. Assume you have an object class of Student. -``java +```java public class Student { int studentId; String studentName; @@ -28,27 +28,27 @@ public class Student { } // setters } -`` +``` Now assume in some method you have a list of all the students and want to get a list of all the student names. Traditionally this can looks something like this. -``java +```java List students = some list of student objects List studentNames = new ArrayList<>(); for(Student student: students) { studentNames.add(student.getStudentName()); } -`` +``` While this isn't terrible it can be simplified. Using streams this is possible with one line of code. -``java +```java List students = some list of student objects List studentNames = students.stream().map(String::getStudentName).collect(Collectors.toList()); -`` +``` The students stream api goes over the list of students and uses the intermediate map function to return a new list of streams using whatever method is on the right of the ::