Class StringApiExamples
java.lang.Object
net.jrodolfo.java_evolution.java11.StringApiExamples
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisBlankText(String text) UsesString.isBlank()to detect text that contains only whitespace.UsesString.lines()to split text into a stream of lines.repeatText(String text, int times) UsesString.repeat(int)to repeat a string.UsesString.strip()to remove leading and trailing Unicode whitespace.
-
Constructor Details
-
StringApiExamples
public StringApiExamples()
-
-
Method Details
-
isBlankText
UsesString.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
UsesString.lines()to split text into a stream of lines.- Parameters:
text- multi-line text- Returns:
- the lines collected in encounter order
-
stripText
UsesString.strip()to remove leading and trailing Unicode whitespace.- Parameters:
text- the text to strip- Returns:
- stripped text
-
repeatText
UsesString.repeat(int)to repeat a string.- Parameters:
text- the text to repeattimes- how many times to repeat it- Returns:
- the repeated text
-