Java: Splitting a string by whitespace when there is a variable number of whitespaces between words?

前端 未结 8 1206
醉话见心
醉话见心 2021-01-01 03:17

I have the following:

String string = \"1-50  of 500+\";
String[] stringArray = string.split(\" \");

Printing out all the elements in this

8条回答
  •  Happy的楠姐
    2021-01-01 03:49

    To fix the space problem, after splitting, you can use .trim() to remove the white space.

    Something like this should work.

    for(int x=0; x

提交回复
热议问题