forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractise.java
More file actions
40 lines (29 loc) · 1.28 KB
/
Practise.java
File metadata and controls
40 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package java8.stream;
import java.util.stream.Stream;
public class Practise {
public static void main(String[] args) {
Character[] chars = {'D', 'B', 'A', 'C'};
System.out.println(Stream.of(chars).sorted().findFirst().get());
System.out.println(Stream.of(chars).sorted(
java.util.Comparator.reverseOrder()).findFirst().get());
System.out.println(Stream.of(chars)
.limit(2).sorted().findFirst().get());
System.out.println(Stream.of(chars).distinct()
.skip(2).filter(e -> e > 'A').findFirst().get());
System.out.println(Stream.of(chars)
.max(Character::compareTo).get());
System.out.println(Stream.of(chars)
.max(java.util.Comparator.reverseOrder()).get());
System.out.println(Stream.of(chars)
.filter(e -> e > 'A').findFirst().get());
System.out.println(Stream.of(chars)
.allMatch(e -> e >= 'A'));
System.out.println(Stream.of(chars)
.anyMatch(e -> e > 'F'));
System.out.println(Stream.of(chars)
.noneMatch(e -> e > 'F'));
Stream.of(chars).map(e -> e + "").map(e -> e.toLowerCase()).forEach(System.out::println);
Object[] temp = Stream.of(chars).map(e -> e + "Y").map(e -> e.toLowerCase()).sorted().toArray();
System.out.println(java.util.Arrays.toString(temp));
}
}