-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
StringFeatures.java
48 lines (37 loc) · 1.24 KB
/
StringFeatures.java
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
45
46
47
48
package java11;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
public class StringFeatures {
/**
* Some new features in the String class
*/
@Test
public void features() {
//Check if value is empty
var empty = "";
System.out.println(empty.isBlank());
//The operator lines allow you separate every element in the string that has new line operator
var numbers =
"1 \n" +
"2 \n" +
"3 \n" +
"4 \n" +
"5 \n";
numbers.lines().forEach(System.out::println);
//Repeat text
var sentence = "Repeat text is handy sometimes \n";
System.out.println(sentence.repeat(5));
//Evolution of trim for unicode
var name = " Paul ";
System.out.println(name.strip());
// Remove the whitespace in the beginning of the string
var name1 = " Paul";
System.out.println(name1.stripLeading());
// Remove the whitespace from the end of the string
var name2 = "Paul ";
System.out.println(name2.stripTrailing());
}
}