-6

Possible Duplicate:
How do I split a string with any whitespace chars as delimiters?

Yes, I tried to search it on google and stackoverflow, but no good results. I have a string, lets say: "Lets do some coding in Java" and I would like to got strings (split it on whitespaces):

Lets, do, some, coding, in, Java

I used string.split("\\s") for this, but know I need to use regex instead. Any ideas?

4

2 回答 2

11
String str = "Hello How are you";
String arrayString[] = str.split("\\s+") 

请使用这个

于 2012-11-21T15:27:21.577 回答
3

要将空格指定为拆分字符,您可以将" "其作为参数传递给String#split. 例子:

String test="Lets do some coding in Java";
    for(String token : test.split(" "))
        System.out.println(token);
于 2012-11-21T15:30:37.200 回答