Tokenization (Split & Parse) - rFronteddu/general_wiki GitHub Wiki
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 "