title: Java String split() delimiter for zero length values
body: <p>I would like to split the following string generated from a database resultset row.</p>
  
  <p>Sample rows:</p>
  
  <p>A) (74,"and there","is a car","in the","garage man",t)</p>
  
  <p>B) (17,account3,,,,t)</p>
  
  <p>I want an output as follows (Pipe | to separate split elements):</p>
  
  <p>A) 74 | and there | is a car | in the | garage man | t</p>
  
  <p>B) 17 | account3 | | | | t</p>
  
  <p>I want to zero length values to be stored as null in my application. This is my source code:</p>
  
  <pre><code>public void refreshSearchTable (ArrayList&lt;String&gt; newData){
          int noOfRows = newData.size();
          int noOfColumns = gui.getTableSearchResultHeader().length + 1;
          Object[][] tempList = new Object[noOfRows][noOfColumns];
          String rowResult = "";
          String delims = "[,()\"]+";
          String [] tokens;
          Object [] elements = newData.toArray();
  
          int j = 0;
          for (int i = 0; i &lt; noOfRows; i++){
              rowResult = elements[i].toString();
              System.out.println("rowresult: " + rowResult);
              tokens = rowResult.split(delims, -1);
              for (String t : tokens){
  
                  System.out.println("j: " + j + "t: " + t);
  
                  if (j == 1){ ... }
                  else if (j==2){ ... }
                                  ...
  
                  j++;
              }
              j=0;
          }
      }
  </code></pre>
  
  <p>"[,()\"]+" works fine for non-zero length values. I'm able to pick up the right sub-string according to index value j. I've read that passing a negative value to split(, ) will not discard the non-zero length values ... but it does. What am i doing wrong?</p>