String的split的学习。
public String[ ] split(String regex);
是根据给定的正则表达式的匹配来拆分此字符串。
正则表达式中的.应该用这种形式来表示:/.
示例代码:
public class TestSplit {
public static void main(String[] args) {
Class c = new String().getClass();
String b = c.toString();
System.out.println(c.getName());
// 使用字符串".",来作为分隔符
String[] temp = b.split(".");
System.out.println("---------------temp.length="+temp.length);
for(int j = 0 ; j < temp.length ; j++){
System.out.println(temp[j]);
}
// 使用转义字符串".",来作为分隔符
String[] temp2 = b.split("//.");
System.out.println("---------------temp2.length="+temp2.length);
for(int j = 0 ; j < temp2.length ; j++){
System.out.println(temp2[j]);
}
}
}