I am using a for loop to extract digits out of a string. The string in question is cdates, which = "MW 130 230". I get an out bounds exception, but I'm using cdates.length() as the limit for the loop. How can it be going out of bounds? Weirdly, the exception occurs when the for loop enters (or tries to enter) iteration # 7. The string is longer than that. What the deuce is going on?!?!
Code:public boolean timeConflictWith(DiaryItem c) {
String thisdt = this.getDaysTimes();
String cdates = c.getDaysTimes();
StringBuffer filter = new StringBuffer(cdates);
String Cee = "";
String Tee = "";
String ctime = "";
boolean conflict = false;
for(int i = 0; i < cdates.length(); i++){
char ch = cdates.charAt(i);
if(Character.isDigit(ch)){
ctime = ctime + ch;
filter.deleteCharAt(i);
}
}
cdates = "" + filter;
cdates.replaceAll("AM","");
cdates.replaceAll("PM","");
cdates.trim();
for(int j = 0; j < cdates.length(); j++) {
if(thisdt.length() < j){
break;
}
else {
char C = cdates.charAt(j);
Cee = " " + C;
}
for(int k = 0; k < thisdt.length(); k++){
char T = thisdt.charAt(k);
Tee = "" + T;
int result = Tee.compareTo(Cee);
if(result != 0)
continue;
else{
String cstart = cdates.substring(0,4);
String cend = cdates.substring(4);
int cstart2 = Integer.parseInt(cstart);
int cend2 = Integer.parseInt(cend);
conflict = cstart2 >= this.starttime && cstart2 < this.endtime ||
cend2 > this.starttime && cend2 <= this.endtime;
return conflict;
}
}
}
return conflict;
}

