Skip to content

Commit df7b235

Browse files
committed
Refine the documentation of the intermediate operations.
1 parent fc33a88 commit df7b235

File tree

2 files changed

+8
-48
lines changed

2 files changed

+8
-48
lines changed
Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,19 @@
1-
# Data Set
2-
3-
```java
4-
List<Footballer> getFootballers() {
5-
return List.of(
6-
new Footballer("Messi", 32, Gender.MALE, List.of("CF", "CAM", "RF")),
7-
new Footballer("Ibrahim", 28, Gender.MALE, List.of("CF", "CAM", "LF")),
8-
new Footballer("Arthur", 23, Gender.MALE, List.of("CM", "CAM")),
9-
new Footballer("Cristiano Ronaldo", 27, Gender.MALE, List.of("GK")),
10-
new Footballer("Surinder", 20, Gender.MALE, List.of("CM", "CDM")),
11-
new Footballer("Jennifer", 29, Gender.FEMALE, List.of("CF", "CAM")),
12-
new Footballer("Jana", 17, Gender.FEMALE, List.of("CB")),
13-
new Footballer("Alexia", 25, Gender.FEMALE, List.of("CAM", "RF", "LF"))
14-
);
15-
}
16-
```
17-
181
# Sorted:
192

203
The `sorted` method is used to sort the stream.
214

22-
#### Example: Sort footballers by Gender and if they have the same gender sort by their names.
235
```java
24-
List<Footballer> sortByGenderAndName= footballerList.stream()
25-
.sorted(Comparator.comparing(Footballer::getGender).thenComparing(Footballer::getName))
26-
.collect(Collectors.toList());
6+
List<Integer> result = List.of(5, 2, 4, 1, 3).stream()
7+
.sorted()
8+
.toList();
279

10+
System.out.println(result);
2811
```
2912

3013
#### Output:
3114

3215
```java
33-
sortByGenderAndName =[
34-
35-
Footballer {
36-
name = 'Arthur', age = 23, gender = MALE, positions =[CM, CAM]},
37-
38-
Footballer {
39-
name = 'Ibrahim', age = 28, gender = MALE, positions =[CF, CAM, LF]},
40-
41-
Footballer {
42-
name = 'Messi', age = 32, gender = MALE, positions =[CF, CAM, RF]},
43-
44-
Footballer {
45-
name = 'Surinder', age = 20, gender = MALE, positions =[CM, CDM]},
46-
47-
Footballer {
48-
name = 'Cristiano Ronaldo', age = 27, gender = MALE, positions =[GK]},
49-
50-
Footballer {
51-
name = 'Alexia', age = 25, gender = FEMALE, positions =[CAM, RF, LF]},
52-
53-
Footballer {
54-
name = 'Jana', age = 17, gender = FEMALE, positions =[CB]},
55-
56-
Footballer {
57-
name = 'Jennifer', age = 29, gender = FEMALE, positions =[CF, CAM]},
58-
]
16+
[1, 2, 3, 4, 5]
5917
```
6018

6119

src/test/java/com/github/streams/learn/a_basics/intermediate_operations/L_MapMulti.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## MapMulti:
22
Instead of creating a new stream for each element, it directly sends the generated values to the next step in the stream.
3-
This makes it simpler and sometimes more efficient when you want to expand or flatten data.
3+
This makes it simpler and sometimes more efficient when you want to expand or flatten data.
4+
Often, you can achieve the same result using filter and map. But the problem with that is we have to use 2 different streams
5+
and do the operations twice. MultiMap allows us to do the both operation of filter and map in one stream thus makes it efficient.
46

57

68
### Example 1:

0 commit comments

Comments
 (0)