| [ Web Proxy ] |
| Viewing: https://tobebetterjavaer.com/string/split.html | [Back] [Original] |
String split()
public class Test {
public static void main(String[] args) {
String cmower = "";
if (cmower.contains("")) {
String [] parts = cmower.split("");
System.out.println("" + parts[0] +" " + parts[1]);
} else {
throw new IllegalArgumentException("");
}
}
} 12
\ArrayIndexOutOfBoundsException^$.|?PatternSyntaxException*+()[]{}GitHub
.
String cmower = ".";
if (cmower.contains(".")) {
String [] parts = cmower.split("\\.");
System.out.println("" + parts[0] +" " + parts[1]);
} split() \\. .
[] .[]
cmower.split("[.]"); Pattern quote() . \Q\E
[]String [] parts = cmower.split(Pattern.quote(".")); split()
return Pattern.compile(regex).split(this, limit); String split()
public class TestPatternSplit {
private static Pattern twopart = Pattern.compile("\\.");
public static void main(String[] args) {
String [] parts = twopart.split(".");
System.out.println("" + parts[0] +" " + parts[1]);
}
}Pattern static
static Pattern Matcher
public class TestPatternMatch {
/**
*
*/
private static Pattern twopart = Pattern.compile("(.+)\\.(.+)");
public static void main(String[] args) {
checkString(".");
checkString(".");
checkString(".");
}
private static void checkString(String str) {
Matcher m = twopart.matcher(str);
if (m.matches()) {
System.out.println("" + m.group(1) + " " + m.group(2));
} else {
System.out.println("");
}
}
} (.+)\\.(.+)
Matcher String split()
String cmower = "";
if (cmower.contains("")) {
String [] parts = cmower.split("(?<=)");
System.out.println("" + parts[0] +" " + parts[1]);
} String [] parts = cmower.split("(?=)");?<= ?=
[]split() 2
String cmower = "";
if (cmower.contains("")) {
String [] parts = cmower.split("", 2);
System.out.println("" + parts[0] +" " + parts[1]);
}debug
[] 2 substring()
GitHub 10000+ Java PDF Java&OOPJava IOJava NIOJVM 32 500+GitHub 10000+ Java
222
[]| Web Proxy Viewer | New URL | Original Page |