两次拆分后的java.lang.ArrayIndexOutOfBoundsException

Zok*_*ker 0 java

我想拆分三次字符串.

这是字符串: 21.06.2016;00:30

我的功能看起来像这样:

String[] split = dateV.split(";");
String[] date = split[0].split(".");
String[] time = split[1].split(":");
Run Code Online (Sandbox Code Playgroud)

date [0]毕竟应该包含"21"

所以第一部分很有效.

我的两个字符串是

split[0] = 21.06.2016
split[1] = 00:30
Run Code Online (Sandbox Code Playgroud)

但是当我打电话给split[0].split(".");我的时候

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

有人可以告诉我为什么吗?

Cri*_*ses 6

String.split 使用正则表达式进行拆分,使用正则表达式时,点是一个特殊字符.

要使用点分割,您需要像这样转义它

String[] date = split[0].split("\\.");
Run Code Online (Sandbox Code Playgroud)