Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java StringTokenizer with empty tokens

I have a string that looks some thing like - 56,0,76,0,93,,,,,,,1230. I use a StringTokenizer to split this by ','. However, it seems that this is skipping from 93 straight to 1230. Is there a way to make it return six empty strings before it moves to 1230?

like image 845
Rohit Pandey Avatar asked Aug 26 '14 07:08

Rohit Pandey


1 Answers

Use String.split() method instead.

String str = "56,0,76,0,93,,,,,,,1230";
String[] stringArr = str.split(",");

This will return an array of String.

like image 195
lxcky Avatar answered Sep 22 '22 17:09

lxcky