I know this is not a new question but I want to sort CSV file by Column preferred in java8.
The Data-structure of CSV is List I need to sort first by one field of the CsvEntity then by other (not must) example by: firstName then by lastName.
class CsvEntity{
private String firstName
private String lastName
private String address
}
What modifications do I need to make for supporting sort on multiple keys in Java8?
解决方案
Just use comparator, an example of sorting by firstName then by lastName
list.forEach(l -> l.sort(Comparator.comparing(CsvEntity::getFirstName)
.thenComparing(CsvEntity::getLastName)));
Of course you have to have getters for your fields to use method reference