StringUtils to split based on comma and space

Adam picture Adam · Sep 17, 2013 · Viewed 17.4k times · Source

Could you please let me know whether we have any StringUtils function to split based on comma and space. Basically i am wondering whether we have any function which will split based on two delimiters. I have written custom function to do the same, but just checking whether we have any good function in any utils package.

The way I have done is to replace first delimiter with second one and then split based on second delimiter.

Answer

Reimeus picture Reimeus · Sep 17, 2013

You can use this version of split, for example

String[] strings = StringUtils.split("some,random words", ", ");

or the built-in split method (as per my comment)

String[] strings = "some,random words".split("[, ]")?