I have a string like this:
one,two,3,(4,five),six,(seven),(8,9,ten),eleven,(twelve,13,14,fifteen)
the above string should split into:
Use Regex.
String s = "one,two,3,(4,five),six,(seven),(8,9,ten),eleven,(twelve,13,14,fifteen)"; Matcher m = Pattern.compile("[^,()]+|\\([^)]*\\)").matcher(s); while (m.find()) System.out.println(m.group());