4 Replies Latest reply: Nov 28, 2006 11:05 AM by 807607 RSS

    Bug in String.split(String regex) method.

    807607
      Hello.
      I think that there is a bug in the split() method of the String class.

      I used the character #124 ("|") has a column separator in a file, but when I try to split the information into a String array, the result is an array of just one char per index:

      Example:

      //Works Well:
      String works = "This,Conversion,Works,Well";
      String[] result = works.split(",");


      The result is {"This", "Conversion", "Works", "Well"}

      //Doesn't works
      String error = "This|Conversion|doesn't|Works";
      String[] result = error.split("|")


      The result is {"T","h","i","s","|","C","o" =>etc.

      Is the same result if we use an empty string has regex.
      Is that a Java bug?
      Or I'm missing something?