title: Java split() method strips empty strings at the end?
body: <p>Check out the below program. </p>
  
  <pre><code>try {
      for (String data : Files.readAllLines(Paths.get("D:/sample.txt"))){
          String[] de = data.split(";");
          System.out.println("Length = " + de.length);
      }
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Sample.txt:</p>
  
  <pre>
  1;2;3;4
  A;B;;
  a;b;c;
  </pre>
  
  <p>Output:</p>
  
  <pre>
  Length = 4
  Length = 2
  Length = 3
  </pre>
  
  <p>Why second and third output is giving 2 and 3 instead of 4. In <code>sample.txt</code> file, condition  for 2nd and 3rd line is should give newline(<code>\n</code> or enter) immediately after giving delimiter for the third field. Can anyone help me how to get length as 4 for 2nd and 3rd line without changing the condition of the <code>sample.txt</code> file and how to print the values of <code>de[2]</code> (throws  <code>ArrayIndexOutOfBoundsException</code>)?</p>