Among other changes, JDK 11 introduces 6 new methods for java.lang.String class:
repeat(int)
- Repeats the String as many times as provided by the int
parameter
lines()
- Uses a Spliterator to lazily provide lines from the source string
isBlank()
- Indicates if the String is empty or contains only white space characters
stripLeading()
- Removes the white space from the beginning
stripTrailing()
- Removes the white space from the end
strip()
- Removes the white space from both, beginning and the end of string
In particular, strip()
looks very similar to trim()
. As per this article strip*()
methods are designed to:
The String.strip(), String.stripLeading(), and String.stripTrailing()
methods trim white space [as determined by Character.isWhiteSpace()]
off either the front, back, or both front and back of the targeted
String.
String.trim()
JavaDoc states:
/**
* Returns a string whose value is this string, with any leading and trailing
* whitespace removed.
* ...
*/
Which is almost identical to the quote above.
What exactly the difference between String.trim()
and String.strip()
since Java 11?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…