Class StringApiExamples

java.lang.Object
net.jrodolfo.java_evolution.java11.StringApiExamples

public class StringApiExamples extends Object
Demonstrates String API additions introduced in Java 11.

Before Java 11, common string operations such as checking for blank text, splitting into lines, stripping Unicode-aware whitespace, and repeating text often required helper code or less precise alternatives.

Java 11 added small but useful methods for those cases: String.isBlank(), String.lines(), String.strip(), and String.repeat(int).

  • Constructor Details

    • StringApiExamples

      public StringApiExamples()
  • Method Details

    • isBlankText

      public boolean isBlankText(String text)
      Uses String.isBlank() to detect text that contains only whitespace.
      Parameters:
      text - the text to inspect
      Returns:
      whether the text is empty or contains only whitespace
    • lines

      public List<String> lines(String text)
      Uses String.lines() to split text into a stream of lines.
      Parameters:
      text - multi-line text
      Returns:
      the lines collected in encounter order
    • stripText

      public String stripText(String text)
      Uses String.strip() to remove leading and trailing Unicode whitespace.
      Parameters:
      text - the text to strip
      Returns:
      stripped text
    • repeatText

      public String repeatText(String text, int times)
      Uses String.repeat(int) to repeat a string.
      Parameters:
      text - the text to repeat
      times - how many times to repeat it
      Returns:
      the repeated text