- 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 BooleanSupplier in lambda expression in Java?
BooleanSupplier is a functional interface defined in the "java.util.function" package. This interface can be used as an assignment target for a lambda expression or method reference. BooleanSupplier interface has only one method getAsBoolean() and returns a boolean result, true or false.
Syntax
@FunctionalInterface public interface BooleanSupplier { boolean getBoolean(); }
Example
import java.util.function.BooleanSupplier; public class BooleanSupplierLambdaTest { public static void main(String[] args) { BooleanSupplier Obj1 = () -> true; BooleanSupplier Obj2 = () -> 5 < 50; // lambda expression BooleanSupplier Obj3 = () -> "tutorialspoint.com".equals("tutorix.com"); System.out.println("Result of Obj1: " + Obj1.getAsBoolean()); System.out.println("Result of Obj2: " + Obj2.getAsBoolean()); System.out.println("Result of Obj3: " + Obj3.getAsBoolean()); } }
Output
Result of Obj1: true Result of Obj2: true Result of Obj3: false
Advertisements