public void addClimb(String peakName, int climbTime){
for(int i = 0; i < climbList.size()-1; i++){
if(peakName.substring(0,1).compareTo(climbList.get(i).getName().substring(0,1)) <= 0){
climbList.add(i, new ClimbInfo(peakName, climbTime));
} else {
climbList.add(new ClimbInfo(peakName, climbTime));
}
}
}
The Goal is to have it take in an peakName and climbTime, have it loop through the climbTime objects in climbList, check for when the first letter of the parameter comes before the first letter of the climbTime in the loop, and places it as soon as that happens, but im getting an out of bounds error when i enter in several ClimbInfos and try to print them. This method is not properly inserting the ClimbInfo into climbTime properly.
Could someone explain what I'm doing wrong?