Why does a single channel symbol mix java split method?

Try the following:

String[] = "abcde|12345|xyz".split("|"); 

The results will not be as expected (at least I ..).

Using any other character looks fine.

 String[] = "abcde,12345,xyz".split(","); 

So what's so special about the pipe?

+4
source share
2 answers

Java String.split () expects RegExp and the pipe character to have a special value in RegExps, except for a comma. Try the following:

 String[] = "abcde|12345|xyz".split("\\|"); 
+15
source

The split method expects a regular expression, and "|" is a special symbol in the world of regular expressions: http://www.tutorialspoint.com/java/java_string_split.htm

+7
source

Source: https://habr.com/ru/post/1501981/


All Articles