I want to split string by setting all non-alphabet as separator.
String[] word_list = line.split("[^a-zA-Z]");
But with the following input
11:11 Hello World
word_list contains many empty string before “hello” and “world”
Please kindly tell me why. Thank You.
Because your regular expression matches each individual non-alpha character. It would be like separating
on commas.
You will want an expression that matches an entire sequence of non-alpha characters at once such as:
I still think you will get one leading empty string with your example since it would be like separating
",Hello,World"if comma were your separator.