我确实拆分为字符串,但我没有考虑异常。所以错误就出来了。例如,如果字符串是“2012-10-21,20:00:00,”
Here is the codes:
String str = "2012-10-21,20:00:00,,";
String a[] = str.split(",");
String timestamp = a[0] + "T" + a[1];
String temp = a[2];
System.out.println(timestamp);
System.out.println(temp);
这是错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
实际上,a[2] 为空,但我不知道如何处理这个问题。因为在我的字符串数组中,一些重新编码包含了 temp 的值,例如“2012-10-21,20:00:00,90”。
谢谢你。