Class StringIndentExamples

java.lang.Object
net.jrodolfo.java_evolution.java12.StringIndentExamples

public class StringIndentExamples extends Object
Demonstrates String.indent(int), introduced in Java 12.

Before Java 12, adding or removing indentation from multi-line text usually meant splitting lines, modifying each one, and joining them again.

String.indent solves this directly by applying indentation changes to every line. Positive values add spaces, while negative values remove indentation where possible.

  • Constructor Details

    • StringIndentExamples

      public StringIndentExamples()
  • Method Details

    • indent

      public String indent(String text, int spaces)
      Adds indentation to every line.
      Parameters:
      text - the text to indent
      spaces - number of spaces to add
      Returns:
      indented text
    • removeIndent

      public String removeIndent(String text, int spaces)
      Removes indentation from every line.
      Parameters:
      text - the text to adjust
      spaces - number of spaces to remove
      Returns:
      text with indentation removed