I'm using java lambda to sort a list.
how can I sort it in a reverse way?
I saw this post, but I want to use java 8 lambda.
Here is my code (I used * -1) as a hack
Arrays.asList(files).stream()
.filter(file -> isNameLikeBaseLine(file, baseLineFile.getName()))
.sorted(new Comparator<File>() {
public int compare(File o1, File o2) {
int answer;
if (o1.lastModified() == o2.lastModified()) {
answer = 0;
} else if (o1.lastModified() > o2.lastModified()) {
answer = 1;
} else {
answer = -1;
}
return -1 * answer;
}
})
.skip(numOfNewestToLeave)
.forEach(item -> item.delete());
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…