MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/9h404p/java_11_string_api_updates/e68z7xc/?context=9999
r/java • u/pivovarit • Sep 19 '18
52 comments sorted by
View all comments
55
Holy shit isBlank should have existed long ago. Strip though is just replace without parameters
2 u/dpash Sep 19 '18 Strip though is just replace without parametersWhat do you mean by that? -2 u/TheRedmanCometh Sep 19 '18 I mean it's essentially String.replace(" ") and it should be called stripWhitespace or stripSpaces 17 u/dpash Sep 19 '18 edited Sep 19 '18 Space is not the only whitespace character, so no, it's nothing like String.replace(" ", "")Also, .strip() doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented .trim() 0 u/TheRedmanCometh Sep 19 '18 All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested 9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
2
Strip though is just replace without parameters
What do you mean by that?
-2 u/TheRedmanCometh Sep 19 '18 I mean it's essentially String.replace(" ") and it should be called stripWhitespace or stripSpaces 17 u/dpash Sep 19 '18 edited Sep 19 '18 Space is not the only whitespace character, so no, it's nothing like String.replace(" ", "")Also, .strip() doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented .trim() 0 u/TheRedmanCometh Sep 19 '18 All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested 9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
-2
I mean it's essentially String.replace(" ") and it should be called stripWhitespace or stripSpaces
17 u/dpash Sep 19 '18 edited Sep 19 '18 Space is not the only whitespace character, so no, it's nothing like String.replace(" ", "")Also, .strip() doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented .trim() 0 u/TheRedmanCometh Sep 19 '18 All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested 9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
17
Space is not the only whitespace character, so no, it's nothing like String.replace(" ", "")
String.replace(" ", "")
Also, .strip() doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented .trim()
.strip()
.trim()
0 u/TheRedmanCometh Sep 19 '18 All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested 9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
0
All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested
9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
9
The documentation for Character.isWhitespace(int codePoint) lists:
Character.isWhitespace(int codePoint)
It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.
It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').
It is '\t', U+0009 HORIZONTAL TABULATION.
It is '\n', U+000A LINE FEED.
It is '\u000B', U+000B VERTICAL TABULATION.
It is '\f', U+000C FORM FEED.
It is '\r', U+000D CARRIAGE RETURN.
It is '\u001C', U+001C FILE SEPARATOR.
It is '\u001D', U+001D GROUP SEPARATOR.
It is '\u001E', U+001E RECORD SEPARATOR.
It is '\u001F', U+001F UNIT SEPARATOR.
https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)
String.trim() removed anything that was <= ' ', which is a different definition to the above list.
String.trim()
<= ' '
"\u001Bstring".trim().equals("\u001Bstring")
would "incorrectly" be false.
6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
6
Wow I have applications those things would break TIL
3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
3
For now apache.commons.lang3.StringUtils is your friend
apache.commons.lang3.StringUtils
55
u/TheRedmanCometh Sep 19 '18
Holy shit isBlank should have existed long ago. Strip though is just replace without parameters