splitting the java string
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3764687/string-split-not-returning-empty-results">String split not returning empty results</a>  </p>
</blockquote>



<p>I am having a string of words separated by comma(,) and I need to tokenize or split the main string into substrings. For e.g, <code>string="file1,param1,file2,param2,file3,"</code> 
What the string means is, a list of all file names and the parameter passed to it. Like,
for file1--> param1,
file2-->param2 and
file3 nothing parameter exists.</p>

<p>So I need to extract the file names and params, if any. If no params I need to get the empty string("").</p>

<pre><code>import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class XStringTokenizer {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String str = new String("File1,param1,File2,");
        List list = new ArrayList();
        System.out.println(str.split(",").length);
        String[] string = str.split(",");
        for(int i=0;i&lt;string.length;i++){
            list.add(string[i]);
        }
        System.out.println(list);
    }
}
</code></pre>

<p>Current output for the above sample code is [File1,param1,File2] but expected output is [File1,param1,File2,]. Basically I should not miss the end empty string after the 3rd comma in the above <code>str</code> String.</p>
