我想在Java中使用split方法按*拆分字符串。以下是代码:
但是这个程序给了我以下错误:
我稍微修改了代码,使用
我不想使用
String str = "abc*def";
String temp[] = str.split("*");
System.out.println(temp[0]);
但是这个程序给了我以下错误:
Exception in thread "main" java.util.regex.PatternSyntaxException:
Dangling meta character '*' near index 0 *
我稍微修改了代码,使用
'\\*'
作为分隔符,这个方法非常有效。有人能解释一下这种行为吗(或者提供另一种解决方案)?我不想使用
StringTokenizer
。