Filtering 2d Array / Returning Arrayindexoutofboundexception
This is the structure of my 2d array along with the single array public String[] sList() { String list[] = { 'Asia Medic Family Hospital and Medical Center', 'Adven
Solution 1:
If I understand correctly, sList.length
is 16, but your 2d array width is only 5. This means that loop
goes up to 16, but the second index in sSpecialty[loop][loop]
must be less than 5. This is where you get the IndexOutOfBoundsException.
I presume you need to replace the if statement with something like
// ALL filter selected
boolean filtermatch=false;
for(int subloop=0;subloop<sSpecialty[loop].length;subloop++){
if (sSpecialty[loop][subloop].equalsIgnoreCase(thisFilter[5])
) {
filtermatch=true;
}
}
if(filtermatch && sReg[loop].equalsIgnoreCase(thisFilter[0])
&& sAdmin[loop].equalsIgnoreCase(thisFilter[1])
&& sAmbience[loop].equalsIgnoreCase(thisFilter[3])
&& amountTF >= theTuitionFee;){
list.add(sList[loop]);
}
The second loop keeps the second index within bounds.
Post a Comment for "Filtering 2d Array / Returning Arrayindexoutofboundexception"