string split in java is not working as expected giving wrong result
java, split, string
Solution
String#split uses a regular expression as it argument. The pipe character `|` has special meaning (meaning OR) prevents the String from being split internally at every literal `|`.
It should be escaped
text.split("\\|").length
otherwise the complete `String` will be used when determining the length
Problem
``` String text="2|919505485043|2013-08-08 12:57:50|2013-08-08 12:58:04|2013-08-08 12:58:08|ANSWER"; ``` I want to split string using `|`.I have the above string in java.When i used ``` System.out.println(text.split("|").length); ``` I am getting the result 82.What might be the wrong here.