我有问题。 我想检查指定索引的ararylist是否索引是空的。 用户可以输入商店像7个项目到我的数组列表(索引0到6)。 所以我想检查索引7是否为空,如果它是空的,我将循环回到我的RoomSelection()。arraylist isEmpty()疑惑和问题
使用roomInfo(4+ xx)的Im使用IsEmpty。
IsEmpty命令是否用于检查整个数组列表是否为空?
如果是检查整个数组列表,可以使用其他方法检查索引7是否为空?
for (int x = 0; x < (Integer) roomInfo.get(2); x++) {//start of number of room loop(to check how many rooms user input)
for (int i = 0; i < (Integer) roomInfo.get(4 + xx); i++) { //start of number of add-on loop(to check how many add-on user input)
System.out.println("addOns array contains what? : " + addOns); // for my own reference
System.out.println("Enter Add-On option");
ao2 = input.nextInt();
while (ao2 > 4) {
System.out.println("Please enter again! Choose only option 1 to 4");
ao2 = input.nextInt();
}
addOnOpt = addOn[ao2 - 1];
addOns.add(addOnOpt);
addOnPrice = priceAdd[ao2 - 1];
addOns.add(addOnPrice);
System.out.println("Enter quantity required for Add-On option " + (i + 1) + ": ");
quan = input.nextInt();
addOns.add(quan);
xx += 3;
System.out.println(" not null yet");
if ((roomInfo.isEmpty(4 + xx) == true) {//if condition to check whether is the arrayllist of position is not null
System.out.println("null!");
xx = 0;
Selection();
}
}// end of add-on loop
}//end of number of room loop
如果我的索引7没有任何东西,我需要做如果(roomInfo.size()<4 + xx)这将做对吗? – 2012-07-30 10:44:32