显示索引3的OutOfBoundsException,即使数组列表显示大小为5

时间:2017-09-11 10:00:36

标签: java indexoutofboundsexception

int q, k;
String query, s;
q = input.nextInt();

for (k = 0; k < q+1; k++) {
    query = input.nextLine();
    batch.getResult().add_res(query);
    s = (batch.getResult().get_res(k));
    //System.out.println(s);
    String[] ss = s.split(" ");
    for(int l=0;l<ss.length;l++) {
        System.out.printf("%s ", ss[l]);
    }
    System.out.println(ss.length);
    System.out.printf("%s \n",ss[3]);
    System.out.println();        
}

此处代码正确打印出arrayList的内容并返回ss.length = 5,但是当我打印ss[3]时,它会显示OutOfBoundsException

0 个答案:

没有答案