I have a question.
I have several methods of comparison, however, one of the attributes used to make the comparison is double.
There is an error:
Can not invoke compareTo (double) on the primitive type double
I tried converting the double to String
. But he commands wrong.
It sorts by "alphabetical" order.
Example, sort the values like this:
10, 1000, 1002, 20, 30 , 300, 40.
When it was time to sort this out:
10, 20 ,30 ,40 , 300, 1000 e 1002.
Here is my code:
<%!
public static class Empreendimento implements Comparable<Empreendimento>{
// ignorar os construtores, métodos e atributos
// Para ordenar por Menor Preco
public static void ordenaPorMenorPreco(List<Empreendimento> ArrayResultadoBusca) {
Collections.sort(ArrayResultadoBusca, new Comparator<Empreendimento>() {
//@Override
public int compare(Empreendimento emp1, Empreendimento emp2) {
return emp1.getPrecoMenor().compareTo(emp2.getPrecoMenor());
}
});
}
%>