使用正则表达式的Java数组孔
有人能告诉我为什么这个代码在数组[0][4]上有一个洞吗使用正则表达式的Java数组孔,java,regex,arrays,delimiter,Java,Regex,Arrays,Delimiter,有人能告诉我为什么这个代码在数组[0][4]上有一个洞吗 public class Random{ public static void main (String []args){ String [][] array={{"This is a test. A hole here"}}; for(int i=0;i<array.length;i++){ String temp=array[i][0];
public class Random{
public static void main (String []args){
String [][] array={{"This is a test. A hole here"}};
for(int i=0;i<array.length;i++){
String temp=array[i][0];
array[i]=temp.split("[\\:., ]");
}
System.out.print(array[0][4]);
}
}
公共类随机{
公共静态void main(字符串[]args){
字符串[][]数组={{“这是一个测试。这里有一个洞”};
对于(int i=0;i和数组[i]=temp.split(“[\\:,]”;
您的字符串在此处拆分:
This is a test. A hole here
^ ^ ^ ^^ ^ ^
因此,在数组[4]
中得到一个空字符串
使用array[i]=temp.split(“[\\:,]+”;
它将把“.”合并成一个“分割点”,因此它不会在这两个点之间分割
This is a test. A hole here
^ ^ ^ ^^ ^ ^