2

My string (str) is

",2016-06-29,SNET Closed End Municipal Bond Fund,CEFMX,,,,1272.772883,1063620.586,835.6719414,77,,0,,,,"

when I do String arr[] = str.split(","); I am getting arr length 13 instead of 17. Split is not considering commas after 0.

What am I missing here?

hsz
  • 143,040
  • 58
  • 252
  • 308
Swapnil B.
  • 748
  • 7
  • 23

1 Answers1

12

As ever, consult the Javadoc for String.split(String):

Trailing empty strings are therefore not included in the resulting array.

Pass -1 as the second parameter to split to get the empty strings:

str.split(",", -1)
Andy Turner
  • 131,952
  • 11
  • 151
  • 228