大概率是碰到转义字符了,加上双反斜杠即可,示例:
import java.util.Arrays;
public class MySplit {
public static void main(String[] args) {
String string = "aaa&123.cba$321";
System.out.println(Arrays.toString(string.split(".")));
System.out.println(Arrays.toString(string.split("\\.")));
System.out.println(Arrays.toString(string.split("$")));
System.out.println(Arrays.toString(string.split("\\$.")));
}
}
结果:
[]
[aaa&123, cba$321]
[aaa&123.cba$321]
[aaa&123.cba, 21]
Python用多了,java的很多用法都忘掉了…