I need to split a string on any of the following sequences:
1 or more spaces
0 or more spaces, followed by a comma, followed by 0 or more spaces,
0 or more space
Just create regex matching any of your three cases and pass it into split
method:
string.split("\\s*(=>|,|\\s)\\s*");
Regex here means literally
\\s*
)=>|,|\\s
)\\s*
)You can replace whitespace \\s
(detects spaces, tabs, line breaks, etc) with plain space character if necessary.