As Java programmers use it every day, it is our job, but it's too many pits ... So now I want to write the Java Pit Series, today write the first pit string split method.
Split is a common method for everyone. But it has a lot of holes ...
It is known that its parameters are regular expressions, regular special symbols to be escaped, if not escaped, hey, ing .....
Let's do a question: the following
System.out.println ("a". Split (".") ). length); System.out.println ("a". Split ("|") ). length); System.out.println ("a". Split ("{"). length); System.out.println ("a". Split ("}"). length);
If the answer you give is
0
2
Error
1
So that means you're using jdk1.7.
If the answer you give is
0
1
Error
1
So that means you're using jdk1.8.
Just ask if the pit is not ... ..... the god pit of Java ....... ..................
If none of the two are the same, you're going to have to lay the groundwork .......
The same generation of different results ........ ..... 1.7 of the source code for this and pattern split's limit about public string[] Split (charsequence input, int limit)
1.8 of the source code I did not go to see, we can go to see for themselves. Run results
======================================== The first pit of God is written here ==============================
Split jdk1.7 with regular special characters
Java God Pit Series--split