0
I need to sort an array based on the Date field of the same, for that I made this code.
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
for(int i = 0; i < arrayCapacitacaoAux.size(); i++){
String dadosA = (String)arrayCapacitacaoAux.get(i);
String infoA[] = dadosA.split("\\|");
Date dataA = (Date)format.parse(infoA[9]);
for(int j = 0; j < arrayCapacitacaoAux.size()-i; j++){
String dadosB = (String)arrayCapacitacaoAux.get(j);
String infoB[] = dadosB.split("\\|");
Date dataB = (Date)format.parse(infoB[9]);
if (dataA.after(dataB)) {
}
}
}
There are some things I need to say first.
- I didn’t create the code at first, it’s an adjustment so I couldn’t interfere with the code, it follows sample of how the array is populated. Follow sample of how it’s done:
arrayCapacitacaoAux.add(pageContext.getAttribute("data").toString()+"|"+nomeCurso +"|"+local+"|"+imagemApresentacao+"|"+horario +"|"+cargaHoraria +"|"+publicoAlvo+"|"+paginaEdit+"|"+periodo+"|"+dataFinal);
And so I take the data the way it is in the code I posted.
- The idea is that the upper date (AFTER) was always above.
Anyway, I got to this part and kind of got lost, the only time I did Buble Sort was in C, but it doesn’t change so much, the problem is that now I’m using arraylist, can you give me a help on this ? Thank you guys!