r/java • • Sep 19 '18

Java 11 String API Updates

https://4comprehension.com/java-11-string-api-updates/
168 Upvotes

52 comments sorted by

View all comments

Show parent comments

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)