Good Morning!
I'm trying to compare a list by two fields, but the result is not working, can you help me?
I have an example list:
Name - MesesDuracao - Buy
A - 1 - 10
A - 2 - 5
B - 1 - 8
I would like the ordering to look like this:
A-1-10
B-1-8
A-2-5
I'm trying this way:
Collections.sort (testImportados, new Comparator <BeanRelEstatisticaMateriaPrima> () {
@Override
public int compare (BeanRelEstatisticaMateriaPrima p1, BeanRelEstatisticaMateriaPrima p2)
{
int comparison = p1.getMesesduration (). compareTo (p2.getMesesduration ());
return comparison == 0? p1.getQtyBuy (). compareTo (p2.getQtyBuy ()): comparison;
}
});
However, it does only sorting by "getMesesduration ()", it is not sorting by quantity purchased.
Any suggestion?
Thank you