MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/9h404p/java_11_string_api_updates/e69atld/?context=3
r/java • u/pivovarit • Sep 19 '18
52 comments sorted by
View all comments
Show parent comments
9
No, it doesn't. String.strip() strips leading and trailing whitespace as per Character.isWhitespace()
String.strip()
Character.isWhitespace()
http://hg.openjdk.java.net/jdk/jdk/file/3fabe59fe4de/src/java.base/share/classes/java/lang/String.java#l2653
String.trim() strips leading and trailing whitespace where the codepoint is <= \u0020. I.E. it strips too much.
String.trim()
<= \u0020
1 u/_INTER_ Sep 19 '18 edited Sep 19 '18 Right, the description in the article was confusing me:We can easily get rid of all the whitespace from each String now:assertThat(" ".strip()).isEmpty(); 4 u/dpash Sep 19 '18 Yes, the code example is technically right, but doesn't demonstrate the method particularly well.assertThat(" string ".strip(), is("string"));would have been a better example. 0 u/_INTER_ Sep 19 '18 indeed
1
Right, the description in the article was confusing me:
We can easily get rid of all the whitespace from each String now:
assertThat(" ".strip()).isEmpty();
4 u/dpash Sep 19 '18 Yes, the code example is technically right, but doesn't demonstrate the method particularly well.assertThat(" string ".strip(), is("string"));would have been a better example. 0 u/_INTER_ Sep 19 '18 indeed
4
Yes, the code example is technically right, but doesn't demonstrate the method particularly well.
assertThat(" string ".strip(), is("string"));
would have been a better example.
0 u/_INTER_ Sep 19 '18 indeed
0
indeed
9
u/dpash Sep 19 '18 edited Sep 19 '18
No, it doesn't.
String.strip()strips leading and trailing whitespace as perCharacter.isWhitespace()http://hg.openjdk.java.net/jdk/jdk/file/3fabe59fe4de/src/java.base/share/classes/java/lang/String.java#l2653
String.trim()strips leading and trailing whitespace where the codepoint is<= \u0020. I.E. it strips too much.