-1
I need to order a ArrayList
in ascending order by date. For I keep adding values out of order in it. In my ArrayList
has only two fields in each element: data
and valor
. Does anyone know any method I can use?
-1
I need to order a ArrayList
in ascending order by date. For I keep adding values out of order in it. In my ArrayList
has only two fields in each element: data
and valor
. Does anyone know any method I can use?
3
You can use the method sort
of the Collections class. The example below has been adapted of Soen’s reply:
Collections.sort(suaLista, new Comparator<SeuObjeto>() {
public int compare(SeuObjeto o1, SeuObjeto o2) {
if (o1.getDate() == null || o2.getDate() == null)
return 0;
return o1.getDate().compareTo(o2.getDate());
}
});
I managed to do what I wanted using this scheme there. Thanks!
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Edit the question and add what you’ve already done.
– user28595