You have got one String.format
method, that returns a formatted
string: -
String str = String.format("%s%n%20s", "Hello", "Hi everyone!");
System.out.println(str);
%n
in string formatting is used to print a newline
character.
%20s
will right indent the string, and will take 20
charater space.
If you want to print the formatted string, rather than storing it, you can use System.out.format
: -
System.out.format("%s%n%20s", "Hello", "Hi everyone!");