I'm having trouble implementing the Comparator method, to sort the ArrayList of Objects.
I have a class of Entrepreneurship. Whereafter, I create an ArrayList, which is populated from a content manager system.
I added the compareTo method, and it sorts by the Area attribute. But now I also need you to order by quantity of rooms, and toilets.
How could I do this?
Here is the current quote:
<%!
public class Empreendimento implements Comparable<Empreendimento>{
//possui atributos, gets, sets e construtor
public int compareTo(Empreendimento Emp) {
if (this.menorArea < Emp.getMenorArea()) {
return -1;
}
if (this.menorArea > Emp.getMenorArea()) {
return 1;
}
return 0;
}
%>
After the content manager, create the ArrayList with these objects. I make a filter, and then I order. Then I use this:
Collections.sort(ArrayResultadoBusca);