Commit 8a897a1
committed
feat(TokenizerDemo): demonstrate StringTokenizer with different delimiters
What
- Added `TokenizerDemo` class showing multiple delimiter use cases with `StringTokenizer`.
- Supports parsing key-value pairs separated by `;`, `\n`, or spaces.
- Demonstrates behavior when only `=` is specified as a delimiter vs multiple delimiters.
Why
- To illustrate how `StringTokenizer` handles delimiters in real-world text parsing scenarios.
- Helps understand default whitespace handling (space, tab, newline).
- Useful for parsing config files, logs, or simple structured input.
How
- Declared sample `data` strings with `;`, `\n`, or space as separators.
- Created `StringTokenizer` with delimiters `"="` (Example B) or `"=;"` (Example A).
- Iterated over tokens with `hasMoreTokens()` and `nextToken()`.
- Printed each token to verify splitting behavior.
Logic
- `StringTokenizer` breaks the input string into tokens based on specified delimiters.
- If no delimiter provided, default delimiters = whitespace characters.
- Tokens are sequentially retrieved until no more remain.
Real-life applications
- Splitting config or `.properties` file content (`key=value`).
- Parsing command-line or user input strings.
- Tokenizing logs or metadata separated by `;`, newline, or spaces.
Summary
- `TokenizerDemo` shows how to tokenize strings with custom delimiters.
- Demonstrates default whitespace handling.
- Practical for learning string parsing using `StringTokenizer`.
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>1 parent 3bdbe95 commit 8a897a1
2 files changed
Lines changed: 68 additions & 30 deletions
File tree
- Section23JavaIOStreams/String Tokenizer/src/Package2
- Section25CollectionFramework/src/StringTokenizerDemo
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
Lines changed: 0 additions & 30 deletions
This file was deleted.
0 commit comments