首页 > 解决方案 > Split a CSV line with an specific pattern with JAVA

问题描述

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.

标签: java

解决方案


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


推荐阅读