我正面临java.lang.ArrayIndexOutOfBoundsException...。但是我的String包含两个以上的值
String[] elements = { "Allama Iqbal","born","in","Sailkot"};
String str = String.join(",", elements);
String str = String.join(",", elements);
String[] strArray = new String[] {str};
if(strArray[2].equals("NNP") ) {
}
The POS are...Allama//NNP
The POS are...Iqbal//NNP
The POS are...,//,
The POS are...born//VBN
The POS are...,//,
The POS are...in//IN
The POS are...,//,
The POS are...Sailkot//NNP
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
答案 0 :(得分:2)
此
String str = String.join(",", elements);
返回一个字符串。因此,
String[] strArray = new String[] {str};
只有1个元素