Skip to content
Advertisement

Tag: java-io

How to sort files in a stream by partial filename?

I use the following to sort files first by name, then by modification date: Question: how can I refactor the File::getName part to only compare based on partial filename, like: StringUtils.substringBefore(file.getName(), “_”)? 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):

BufferedReader vs Console vs Scanner

Hi I’m new to Java and I would like to know what is the best choice to read a user Input in the console, as far as I know there are 3 ways to do it: Console console = System.console(); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); Scanner reader = new Scanner(System.in); Which one should I choose? Why that one and

Advertisement