Search code examples
javastringtokenizer

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?


Solution

  • Use String.split() method instead.

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

    This will return an array of String.