Java – Split and trim in one shot

Use regular expression \s*,\s* for splitting.

String result[] = attributes.split("\\s*,\\s*");

For Initial and Trailing Whitespaces
The previous solution still leaves initial and trailing white-spaces. So if we’re expecting any of them, then we can use the following solution to remove the same:

String result[] = attributes.trim().split("\\s*,\\s*");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)