Commit 8706fc4
committed
feat(ConvertNumbersIntoArrayList): add program to parse numbers from file into ArrayList
What
- Added ConvertNumbersIntoArrayList in Package.
- Reads a text file containing numbers separated by commas.
- Uses StringTokenizer to split numbers and stores them in an ArrayList<Integer>.
- Prints the resulting list to console.
Why
- Demonstrates file reading and parsing of delimited data.
- Shows how to convert raw text input into structured Java collections.
- Useful for lightweight parsing of CSV-style numeric data.
How
- Opened FileInputStream on a file path containing comma-separated numbers.
- Read file contents into byte array, then converted to String.
- Created StringTokenizer with `","` as delimiter.
- Iterated over tokens, converted each String token to Integer using Integer.valueOf().
- Added integers into ArrayList.
- Printed the ArrayList for verification.
Logic
- FileInputStream reads raw bytes from file.
- new String(b) constructs a string representation of file contents.
- StringTokenizer splits input based on specified delimiter (comma here).
- Integer.valueOf(s) safely parses numeric tokens into Integer objects.
- ArrayList grows dynamically as tokens are parsed.
Real-life applications
- Parsing CSV or configuration files where numbers are stored as comma-separated values.
- Converting external input (from text files, network logs, etc.) into usable Java collections.
- Preprocessing datasets for further computation or analytics.
Summary
- ConvertNumbersIntoArrayList reads a file of comma-separated numbers.
- Splits data into tokens and converts each into Integer.
- Stores parsed integers in ArrayList and prints the final collection.
- Demonstrates integration of File I/O, String processing, and collection handling in Java.
Signed-off-by: https://github.com/Someshdiwan <someshdiwan369@gmail.com>1 parent fb2cf1c commit 8706fc4
2 files changed
Lines changed: 6 additions & 8 deletions
File tree
- Section23JavaIOStreams/String Tokenizer/src/Package
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 8 | + | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | | - | |
23 | | - | |
| 20 | + | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
29 | | - | |
| 26 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments