- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use FileFilter interface in lambda expression in Java?n
A FileFilter is a functional interface from the "java.io" package. It can be used as the assignment target for a lambda expression or method reference. An instance of the FileFilter interface passed to the listFiles() method of the File class. FileFilter interface having one abstract method accept() and it tests whether or not the specified abstract pathname has included in a pathname list.
Syntax
@FunctionalInterface public interface FileFilter
Example
import java.io.File; import java.io.FileFilter; public class FileFilterTest { public static void main(String[] args) { File dir = new File("C:/Program Files/Java/jdk1.8.0_211"); File[] subDir = dir.listFiles((file) -> { // lambda expression return file.isDirectory(); } ); for(File file : subDir) { System.out.println(file.getName()); } } }
Output
bin include jre lib
- Related Articles
- How to use Supplier interface in lambda expression in Java?
- How to use BinaryOperator interface in lambda expression in Java?
- How to use UnaryOperator interface in lambda expression in Java?
- How to implement ObjLongConsumer interface using lambda expression in Java?
- How to implement Function interface with lambda expression in Java?\n
- How to implement the ObjIntConsumer interface using lambda expression in Java?
- How to implement the Runnable interface using lambda expression in Java?
- How to use BooleanSupplier in lambda expression in Java?
- How to use IntSupplier in lambda expression in Java?
- Importance of Predicate interface in lambda expression in Java?
- How to use Predicate and BiPredicate in lambda expression in Java?
- How to use a return statement in lambda expression in Java?
- How to use an ArrayList in lambda expression in Java?\n
- How to use Consumer and BiConsumer interfaces in lambda expression in Java?
- How to use Function and BiFunction interfaces in lambda expression in Java?

Advertisements