i have a csv file like this:
i,0 <-- 1st line
f,1,2,3 <-- 2nd line
s,0,1,2,3,4,5,6 <-- 3rd line
0,1,A
0,5,B
1,1,A
1,3,B
2,6,A
2,4,B
3,6,A
3,4,B
4,6,A
4,4,B
5,1,A
5,5,B
6,6,A
6,2,B
how do i read these line to 4 different array/arraylist in java?
the output i want is something like this:
- 1st line: 0 [1st array]
- 2nd line: 1 2 3 [2nd array] –> just 1 line but the length of the token is unknown
- 3rd line: 0 1 2 3 4 5 6 [3rd array] –> just 1 line but the length of the token is unknown
- rest of the line: –> fixed 3 token, but the number of the row is unknown
0 1 A
0 5 B
1 1 A
1 3 B
2 6 A
2 4 B
3 6 A
3 4 B
4 6 A
4 4 B
5 1 A
5 5 B
6 6 A
6 2 B
can’t get it right with the combination of scanner and switch-case condition..
I would not use
switch. Just read the file line by line. If the file is generated (or you are otherwise sure that it is correct) than you could read it likeand implement every
read...method to handle one line format.Update: The read methods could look something like