First strip out the [
and ]
from the string using replaceAll()
. Then split using \s*,\s*
which means comma can have optional space before or after it.
String []splits = text.replaceAll("^\\s*\\[|\\]\\s*$", "").split("\\s*,\\s*");
Now convert the String
array into List
using Arrays.asList()
.