Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading one line delimited by both comma and space - java

I am willing to read a series of number from one line like below in Java:

1   80,982  163,8164                    170,2620    

So eventually I want the result array [1, 80, 982, 163, 8164, 170, 2620]

I am thinking about using scanner, but not clear how to implement it in a neat way, can I ask some tips please?

Thanks for reading!

like image 757
Bpache Avatar asked Nov 30 '22 01:11

Bpache


1 Answers

If it were me, I'd read one line using BufferedReader and then simply use

String[] values = line.split("[, ]");

I usually find Scanner untidy and overkill.

like image 137
Mark Peters Avatar answered Dec 21 '22 20:12

Mark Peters