Skip to content
Advertisement

Trying to reverse my stream in ascending order – Java 8

This idea behind this code is that it reads the data from three .csv files w/ keys organized by year, and retrieves the sum of the data by year, as well as the minimum and maximum number for each year.

The problem is, when print it returns the yearly results in descending order.

I need help figuring out a way to reverse the stream, so that yearly data from each file is in ascending order.

JavaScript

Note: TeslaImport is the class where I placed my JavaBean’s (get/set, toString, date, and sales)

Advertisement

Answer

As the report data are printed for the entry set retrieved from the method entryByYear in TeslaModel class, it is very likely that this method returns the entry set for a tree map sorted in the descending order. Thus, to change the order, the stream should be re-sorted by key:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement