I am trying to sort a static array of Ticket objects into two different arrays based on their dates and Class
. These two arrays will be used as data to populate two different list
views. I only want to add one Ticket per Class
object to each array
. I get an error
ArrayList<Ticket> myUpcomingTickets = new ArrayList<>();
ArrayList<Ticket> myPastTickets = new ArrayList<>();
for (Ticket t : Ticket.getTickets()) {
if (t.getClass().getDate().after(date)) {
if(myUpcomingTickets.isEmpty()){
myUpcomingTickets.add(t);
}else {
for(Ticket t1: myUpcomingTickets) {
if (!t.getClass().getId().equals(t1.getClass().getId())) {
myUpcomingTickets.add(t);
}
}
}
} else {
if(myPastTickets.isEmpty()){
myPastTickets.add(t);
} else {
for(Ticket t2: myPastTickets) {
if (!t.getClass().getId().equals(t2.getClass().getId())) { //Add if not already there
myPastTickets.add(t);
}
}
}
}
}
Error Show in Logcat
java.util.ConcurrentModificationException