一个小例子:以字符q拆分字符串s
String s = "AqBqC";
String []str = s.split("q");
for(int i=0;i
System.out.println(str[i]);
}
输出:
A
B
C
以字符*拆分字符串s
String s = "A*B*C";
String []str = s.split("[*]");
for(int i=0;i
System.out.println(str[i]);
}
输出:
A
B
C
特殊字符拆分时,如果不加[],一般会报这样的异常:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta. character '*' near index 0
*
^
String s = "AqBqC";
String []str = s.split("q");
for(int i=0;i
System.out.println(str[i]);
}
输出:
A
B
C
以字符*拆分字符串s
String s = "A*B*C";
String []str = s.split("[*]");
for(int i=0;i
System.out.println(str[i]);
}
输出:
A
B
C
特殊字符拆分时,如果不加[],一般会报这样的异常:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta. character '*' near index 0
*
^
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26668320/viewspace-722763/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26668320/viewspace-722763/