forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamDemo.java
More file actions
43 lines (27 loc) · 1.21 KB
/
StreamDemo.java
File metadata and controls
43 lines (27 loc) · 1.21 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
41
42
43
package stream;
import java.util.Arrays;
import java.util.stream.Stream;
public class StreamDemo {
public static void main(String[] args) {
String[] names = {"John", "Peter", "Susan", "Kim", "Jen", "George", "Alan", "Stacy", "Michelle",
"john"};
Stream.of(names).limit(4).sorted().forEach(e -> System.out.println(e + " "));
System.out.println();
Stream.of(names).skip(4).sorted((e1, e2) -> e1.compareToIgnoreCase(e2)).forEach(e -> System.out
.println(e + " "));
System.out.println();
Stream.of(names).skip(4).sorted(String::compareToIgnoreCase).forEach(e -> System.out
.println(e + " "));
System.out.println();
System.out.println(Stream.of(names).anyMatch(e->e.equals("Stacy")));
System.out.println();
System.out.println(Stream.of(names).allMatch(e->Character.isUpperCase(e.charAt(0))));
System.out.println();
System.out.println(Stream.of(names).noneMatch(e->e.startsWith("Ko")));
System.out.println();
System.out.println(Stream.of(names).map(e->e.toUpperCase()).distinct().count());
System.out.println();
Object[] array=Stream.of(names).map(String::toLowerCase).toArray();
System.out.println(Arrays.toString(array));
}
}