Java God Pit Series--split

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.