The use of the split method in Java

Source: Internet
Author: User

The reason why I want to figure this out is that I can't find all the words in a text, because when I touch C + + I remember it seems like a regex can have a lot of characters, so you can pass,. and whitespace punctuation to split the text, but the split method accepts arguments with only the string type of regex and the limit,limit of the int type to represent the maximum number of parts that can be divided into a string. Later by looking for information on the Internet to know that the original string type of regex can be composed of multiple parts, each part by | Separated, may need to appear the * +. and other symbols, may require \ \ 's escape, the specific considerations have the following parts:

1. First. * + | are key characters, and they must be escaped with \ \ to divide them.

2. Multiple split characters to connect is needed | Character

3. If you use \ as a delimiter, you have to write: Str.split ("\\\\"), because in Java is "\ \" to denote "\", the string is written like this: "String str=" a\\b\\c ";

Chestnut One:


String Str1=new string ("hello+world| I ' m*mnmlist.sting "); String regexstring= "|,|\\.| \\*|\\+|\\|"; String Arr1[]=str1.split (regexstring); for (int i=0;i<arr1.length;i++) System.out.println (Arr1[i]);




The use of the split method in Java

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.