0

I dont know if my question makes sense or not, but i am facing this problem

Case 1:

String fileLine  ="->->->6";
System.out.println(fileLine.split("\t").length);

output: 4

Case 2:

String fileLine  ="1->->->6";
System.out.println(fileLine.split("\t").length);

output: 4

The Problem Case:

String fileLine  ="1->6->->";
System.out.println(fileLine.split("\t").length);

output: 2

Can anyone tell me why is that and to capture this situation?

I want to capture the tabs in the end of the line as well even if the file end is empty

Thanks

Wasif Tanveer
  • 139
  • 3
  • 19
  • 1
    [Always read the Javadoc](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)): "Trailing empty strings are therefore not included in the resulting array." Use `split("\t", -1)` instead. – Andy Turner Nov 23 '16 at 11:00
  • thanks Andy i could not find the exact word to search for that question thanks for guiding.. – Wasif Tanveer Nov 24 '16 at 02:23

0 Answers0