-1

I am reading a CSV file with Java. I am storing each value between commas into a String Array.

This is what prints when I read a CSV line:

Tania, Joe, Pat, , , , , , ,

When I store this line into a String Array: String [] myString = line.split(",");

I get this output when I print my string: [Tania, Joe, Pat]

And I want to get: [Tania, Joe, Pat, , , , , , ,]

I want to store the empty spaces as well.

RobertoC
  • 1
  • 2

2 Answers2

0

You should have checked Stackoverflow site, use line.split(",",-1).

DuncG
  • 12,137
  • 2
  • 21
  • 33
0

Add a limit to get a specific number of entries

line.split("<regex>",<limit>)

from here: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String,%20int)

Lovelin B
  • 60
  • 3