Woj*_*cki 5 java java-text-blocks
Given the following code
public class TextBlock {
public static void main(String[] args) {
String indentedText = """
hello
indented
world
""";
System.out.println(indentedText);
}
}
Run Code Online (Sandbox Code Playgroud)
The output is as follows (mind the leading spaces):
hello
indented
world
Run Code Online (Sandbox Code Playgroud)
How to obtain String value like below (without unnecessary leading spaces)?
hello
indented
world
Run Code Online (Sandbox Code Playgroud)
Woj*_*cki 12
You can manipulate indentation by changing closing quotes position in the code ("""). For example
String indentedText = """
hello
indented
world
""";
System.out.println(indentedText);
Run Code Online (Sandbox Code Playgroud)
Would produce
hello
indented
world
Run Code Online (Sandbox Code Playgroud)
but
String indentedText = """
hello
indented
world
""";
System.out.println(indentedText);
Run Code Online (Sandbox Code Playgroud)
will produce
hello
indented
world
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1382 次 |
| 最近记录: |