Given the following input:
-100 50 0 56.6 90
I added each value as BigDecimal to the list.
I want to sort the list from highest to lowest.
I tried to do it as follows:
public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<BigDecimal> list = new ArrayList<BigDecimal>(); while(sc.hasNext()){ list.add(new BigDecimal(sc.next())); } Collections.reverse(list); for(BigDecimal d : list){ System.out.println(d); } }
What outputs:
90 56.6 0 50 -100
In this case, 50 should be a higher value than 0.
How to correctly sort the BigDecimal list from highest to lowest, taking into account decimal and decimal values?
source share