Skip to content
Advertisement

How to sort files in a stream by partial filename?

I use the following to sort files first by name, then by modification date:

JavaScript

Question: how can I refactor the File::getName part to only compare based on partial filename, like: StringUtils.substringBefore(file.getName(), "_")?

Advertisement

Answer

You could replace the method reference with a lambda expression on the File object, although you’ll have to specify the types (see the additional discussion here):

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