Splitting a String into tokens

12,084

How about

String[] tokens = yourString.split("\\s+");

Split uses regex and in regex

  • to represent any whitespace you can use "\\s"
  • to say "one or more times" use +
Share:
12,084
user2682570
Author by

user2682570

Updated on June 14, 2022

Comments

  • user2682570
    user2682570 almost 2 years

    I would like to split a String into tokens that are stored in an array. However i don not think I am able to use delimiters as the strings information is not separated by a specific set of characters. The information is however always separated by varying amounts of white space.

    Like this:

    0      147    530.936        1    656.336   -1.12709    656.336   -0.52921 -0.0131993  -0.882138        0       20        0        0   0.878423          0 1.4013E-045          0    
    

    My question is, is there a way to use the varying amounts of white space as delimiters, in order to tokenize the string?