我的代码是:-
class SplitString {
public static void main(String[] args) {
Pattern p;
String test = "a1b2c3";
String[] token1 = test.split("\\d");
System.out.println("first case : " + token1.length);
for (String s : token1)
System.out.print(s + " ");
String[] token2 = test.split("\\b");
System.out.println("\n\nsecond case : " + token2.length);
for (String s : token2)
System.out.print(s + " ");
String[] token3 = test.split("\\a");
System.out.println("\n\nthird case : " + token3.length);
for (String s : token3)
System.out.print(s + " ");
}
}
输出:-
first case : 3
a b c
second case : 2
a1b2c3
third case : 1
a1b2c3
我是 java 新手,试图执行 split 但无法掌握它的概念,因为所有案例都有不同的答案,但它们之间到底有什么区别?