I notice strange behavior when using a method split()in Java.
I have a line as follows: 0|1|2|3|4|5|6|7|8|9|10
String currentString[] = br.readLine().split("\\|");
System.out.println("Length:"+currentString.length);
for(int i=0;i < currentString.length;i++){
System.out.println(currentString[i]);
}
This will lead to the desired results:
Length: 11
0
1
2
3
4
5
6
7
8
9
10
However, if I get the line: 0|1|2|3|4|5|6|7|8||
I get the following results:
Length: 8
0
1
2
3
4
5
6
7
8
The last two empty devastations are omitted. I need empty leftovers. Not sure what I'm doing wrong. I also tried to use a split this way ....split("\\|",-1);
but returns the entire string of length 1.
Any help would be greatly appreciated!
source
share