forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString1.java
More file actions
44 lines (37 loc) · 1.15 KB
/
String1.java
File metadata and controls
44 lines (37 loc) · 1.15 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
44
package com.winterbe.java8.samples.misc;
import java.util.function.Predicate;
import java.util.regex.Pattern;
/**
* @author Benjamin Winterberg
*/
public class String1 {
public static void main(String[] args) {
testJoin();
testChars();
testPatternPredicate();
testPatternSplit();
}
private static void testChars() {
String string = "foobar";
string.chars()
.filter(c -> c > 100)
.mapToObj(c -> (char)c)
.forEach(System.out::println);
}
private static void testPatternSplit() {
Pattern.compile(":")
.splitAsStream("foobar:foo:bar")
.sorted()
.forEach(System.out::println);
}
private static void testPatternPredicate() {
Pattern pattern = Pattern.compile(".*123.*");
Predicate<String> predicate = pattern.asPredicate();
System.out.println(predicate.test("a123b"));
System.out.println(predicate.test("boom"));
}
private static void testJoin() {
String string = String.join(";", "a", "b", "c", "d");
System.out.println(string);
}
}