Skip to content

Tokenization (Split & Parse)

Roberto Fronteddu edited this page Feb 3, 2026 · 2 revisions

When: Space-separated, CSV, mixed text+numbers Techniques:

  • split(" "), split(",")
  • Regex: split("\s+"): matches any run of whitespace, no matter how long. Collapses multiple spaces/tabs/newlines into a single delimiter (note the need to do the escape in the string literal).

Avoids empty strings in the result

  • Streaming tokenizers: Scanner, StringTokenizer, stringstream

Practice Cases

"10  20   30"
"1,2,3,4"
"   -15 42   7  "

Clone this wiki locally