参数:
regex - 定界正则表达式
limit - 结果阈值,如上所述
返回:
字符串数组,根据给定正则表达式的匹配来拆分此字符串,从而生成此数组
抛出:
PatternSyntaxException - 如果正则表达式的语法无效
示例代码:
String value = "boo.and.foo";
String[] names = value.split("\\.",2);for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
结果:
Regex Limit 结果
: 2 { "boo", "and:foo" }
: 5 { "boo", "and", "foo" }
: -2 { "boo", "and", "foo" }
o 5 { "b", "", ":and:f", "", "" }
o -2 { "b", "", ":and:f", "", "" }
o 0 { "b", "", ":and:f" }