Last active
October 10, 2021 02:39
-
-
Save nowshad-hasan/530577ae5d0be3e0c5e076c66d84032a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String input = "Hello Java 17!\nIt's a new LTS."; | |
public static void indentString(String input) { | |
// Positive value add spaces beginning of each line. | |
String positiveIndent5 = input.indent(5); // 5 spaces | |
/* | |
1. Hello Java 17! | |
It's a new LTS. | |
*/ | |
// Negative value remove spaces from each line. | |
String negativeIndent2 = positiveIndent5.indent(-2); // 3 spaces | |
/* | |
1. Hello Java 17! | |
It's a new LTS. | |
*/ | |
// For negative value, if the value is greater than the actual spaces the string actually has, | |
// it removes all the spaces. | |
String negativeIndent10 = positiveIndent5.indent(-10); // no space | |
/* | |
1.Hello Java 17! | |
It's a new LTS. | |
*/ | |
} | |
// transform(java.util.function.Function function) takes a Function to transform a string. | |
public static void transformString(String input) { | |
input.transform(s -> s.trim()) | |
.transform(s -> s.toUpperCase()) | |
.transform(s -> s.lines()) | |
.forEach(s -> System.out.println(s)); | |
/* | |
HELLO JAVA 17! | |
IT'S A NEW LTS. | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment