September 2019
Intermediate to advanced
816 pages
18h 47m
English
Starting with JDK 12, we can indent text via the String.indent(int n) method.
Let's assume that we have the following String values:
String days = "Sunday\n" + "Monday\n" + "Tuesday\n" + "Wednesday\n" + "Thursday\n" + "Friday\n" + "Saturday";
Printing this String values with an indentation of 10 spaces can be done as follows:
System.out.print(days.indent(10));
The output will be as follows:

Now, let's try a cascade indentation:
List<String> days = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");for (int i = 0; i < days.size(); i++) { System.out.print(days.get(i).indent(i)); ...