String a=new String("aader");
String str[]=a.split(".");
int max=str.length;
System.out.println(max);
点(.
)表示每个字符。
所以它应该分割a的每个字符。但是当我运行代码时 max = 0
。为什么?
最佳答案
在正则表达式中,DOT 表示任意字符而不是每个字符。在java中“|”被视为每个角色。所以你可以尝试类似的东西 字符串 a = new String("aader");
String[] result = a.split("");
或
String[] result = a.split("|");
关于java - 在java中的正则表达式中使用点进行分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48954834/