Home> Java> javaTutorial> body text

How to use split() method in Java

angryTom
Release: 2020-03-02 17:06:28
Original
2750 people have browsed it

How to use split() method in Java

How to use the split() method in Java

Split in Java is mainly used to separate strings.

The specific analysis is as follows:

1. If "." is used as the separation, it must be written as follows, String.split("\\."), so that it can be separated correctly ,String.split(".") cannot be used.

2. If "|" is used as a separation, it must be written as follows, String.split("\\|"), so that it can be separated correctly. String.split("|" cannot be used ), "." and "|" are all escape characters, and "\\" must be added.

3. If there are multiple delimiters in a string, you can use "|" as a hyphen, for example, "acount=? and uu =? or n=?" to separate all three To get it out, you can use String.split("and|or").

(Related video tutorial sharing:java video tutorial)

Notes on using split in Java:

1. The decomposed String object or text will not be modified by the split method.

2. String or regular expression object, which identifies whether one or more characters are used to separate the string. If this option is omitted, a single-element array containing the entire string is returned.

3. This value is used to limit the number of elements in the returned array (that is, it can be divided into several array elements at most, and it only affects positive numbers).

4. The result of the split method is a string array, which must be decomposed at every position where separator appears in stingObj. separator is not returned as part of any array element.

For more Java tutorials, please pay attention to theJava tutorial column.

The above is the detailed content of How to use split() method in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!