https://blog.youkuaiyun.com/qq_44750696/article/details/124538073
public String[] split(String regex)
将此字符串拆分为给定的regular expression的匹配。
该方法的工作原理是通过使用给定表达式和限制参数为零调用双参数split方法。 因此,尾随的空字符串不会包含在结果数组中。
例如,字符串"boo:and:foo"使用以下表达式得到以下结果:
这个split方法简单来说以这个regex字符分割 然后形成字符串数组 对于分割数组来说分割符号删除
Regex Result
: { “boo”, “and”, “foo” }
o { “b”, “”, “:and:f” }
参数
regex - 分隔正则表达式
结果
通过将该字符串围绕给定的正则表达式的匹配来计算的字符串数组
异常
PatternSyntaxException - 如果正则表达式的语法无效
-
Regex Result
- { “boo”, “and”, “foo” }
o { “b”, “”, “:and:f” }
Parameters:
regex -定义的正则表达式
Returns:
通过分裂这个字符串来计算给定正则表达式的匹配的字符串数组
Throws:
PatternSyntaxException如果正则表达式的语法是无效的
Since:
一点四
See Also:
Pattern
package com.ReviewProperties.java;
public class SplitTest {
public static void main(String[] args) {
String str="boo:and:foo";
String[] strings=str.split(":");
for (String str1:strings
) {
System.out.println(str1);
}
// String[] strings1=str.split("o");
// for(int i=0;i<strings1.length;i++){
// System.out.println(strings1[i]);
// }
}
}
boo
and
foo