2
I’m having trouble implementing the Comparator method, to sort the Object Arraylist.
I have an Enterprise class. Where I then create an Arraylist, which is filled from a content manager system.
I added the method compareTo, and it sorts by the Area attribute. But now I also need you to sort by number of rooms, and bathrooms.
How could I do that ?
Here is the current cider:
<%!
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 obejtos. I make a filter, and then I order. Then I use this:
Collections.sort(ArrayResultadoBusca);
would like to add an Addendum on Arraylist: here. I believe I can help you understand your question.
– pss1suporte