Edit: Raw String Literals have been dropped from JDK 12, but I'm going to leave this question open and will edit it accordingly whenever Raw String Literals are reintroduced.
When testing Raw String Literals (which are a preview feature in Java 12), I came across the following snippet of code:
System.out.println(`
Test 1
Test 2
Test 3
`);
Which outputs the following:
Test 1
Test 2
Test 3
However, I want the output to resemble the following:
Test 1
Test 2
Test 3
What is the easiest way to remove the leading indentation to match the intended format?
Accompanying Raw String Literals as a preview feature in Java 12 are new methods that will be added to
java.lang.String
, one of which isString#align
. Its documentation states the following:To use this method, we can change the code to the following:
Which outputs the following (suffixed with a line feed character, as stated by the documentation):