MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/9h404p/java_11_string_api_updates/e69phln/?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. 2 u/xenomachina Sep 19 '18 Some interior whitespace would be even better. What does this do?" a string ".strip() 1 u/dpash Sep 19 '18 "a string" 2 u/xenomachina Sep 19 '18 So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace. → More replies (0)
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. 2 u/xenomachina Sep 19 '18 Some interior whitespace would be even better. What does this do?" a string ".strip() 1 u/dpash Sep 19 '18 "a string" 2 u/xenomachina Sep 19 '18 So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace. → More replies (0)
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.
2 u/xenomachina Sep 19 '18 Some interior whitespace would be even better. What does this do?" a string ".strip() 1 u/dpash Sep 19 '18 "a string" 2 u/xenomachina Sep 19 '18 So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace. → More replies (0)
2
Some interior whitespace would be even better. What does this do?
" a string ".strip()
1 u/dpash Sep 19 '18 "a string" 2 u/xenomachina Sep 19 '18 So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace. → More replies (0)
"a string"
2 u/xenomachina Sep 19 '18 So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace. → More replies (0)
So when the article uses "We can easily get rid of all the whitespace from each String" in its despription of strip, it's just wrong. strip only removes leading and trailing whitespace.
strip
→ More replies (0)
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.