I'm trying to order a list of time spans (represented as Time[] arrays with a start time and end time) by their start times. I'm trying to use the following nested loop to do so:
for (Time[] span : workingList){
Time[] compareTo = workingList.get(0);
for (Time[] inSpan : workingList){
if (inSpan[0].before(compareTo[0])){
compareTo = inSpan;
}
}
workingList.remove(compareTo);
toReturn.add(compareTo);
}
}
but it is throwing a java.util.ConcurrentModificationException
at the line for (Time[] span : workingList)
(the one on top). I've never seen this exception before, can someone please explain to me what it means and what causes it.
I'm also open to suggestions of better algorithms for this.