A quick Java interview Q&A covering how to list directory contents. It compares the legacy File class methods (list, listFiles with optional FileNameFilter) against the modern Files factory class methods (walkFileTree with a FileVisitor, and walk returning a Stream<Path>). The preferred approach uses the Path interface and Files class, which support multiple file systems and offer more flexibility than the older File class.

1m watch time

Sort: