-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringNewMethods.java
More file actions
26 lines (18 loc) · 952 Bytes
/
Copy pathStringNewMethods.java
File metadata and controls
26 lines (18 loc) · 952 Bytes
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
package Java12;
public class StringNewMethods {
public static void main(String[] args) {
//new String methods introduced in java 12
//indent(int n) method is used to return a string whose value is the concatenation of the specified string repeated n times.
//If n is negative, then the method returns the original string.
String str = "Hello";
System.out.println(str.indent(5));//" Hello"
System.out.println(str.indent(-5));//"Hello"
//transform(Function<? super String, ? extends R> f) method is used to return a string whose value is the result of applying the given function to the string.
//The given function should not be null.
str = str.transform(s -> s + " World");
System.out.println(str);//"Hello World"
//list all new string method introduced in java 12
//1. indent(int n) method
//2. transform(Function<? super String, ? extends R> f) method
}
}