Possible Duplicate:
How to split a String by space
I need help while parsing a text file.
The text file contains data like
This is different type of file.
Can not split it using ' '(white space)
My problem is spaces between words are not similar. Sometimes there is single space and sometimes multiple spaces are given.
I need to split the string in such a way that I will get only words, not spaces.
str.split("\\s+")would work. The+at the end of the regular-expression, would treat multiple spaces the same as a single space. It returns an array of strings (String[]) without any" "results.