Raja has Published 760 Articles

How to use BinaryOperator interface in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 07:29:22

637 Views

BinaryOperator is one of a functional interface from java.util.function package and having exactly one abstract method. A lambda expression or method reference uses BinaryOperator objects as their target. BinaryOperator interface represents a function that takes one argument of type T and returns a value of the same type.BinaryOperator Interface contains two static methods, minBy() and maxBy(). The minBy() method ... Read More

How to use Supplier interface in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 07:22:11

5K+ Views

A Supplier interface is a pre-defined interface that represents the supplier of results. It is instantiated using lambda expression or method reference or default constructor. The functional method of a Supplier interface is the get() method. This interface belongs to java.util.function package.Syntax@FunctionalInterface public interface SupplierIn the below program, we can use the Supplier interface in a lambda expression. ... Read More

How to use Predicate and BiPredicate in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 07:18:22

2K+ Views

A Predicate interface defined in java.util.function package. It represents a boolean-valued function with one argument. It is kind of a functional interface whose functional method is the test(). BiPredicate interface is similar to the Predicate interface with two arguments. It can be used as an assignment target for a lambda expression.Syntax for Predicate@FunctionalInterface public interface PredicateExampleimport java.util.*; import java.util.function.*; ... Read More

How to sort a list by name using a Comparator interface in Java?

raja

raja

Updated on 13-Jul-2020 07:00:37

651 Views

Comparator interface can be used to order the objects of user-defined classes. It is capable of comparing two objects of two different classes. We can sort a list of objects where we can't modify the object’s source code to implement Comparable interface. A lambda expression can't be executed on its own and used to implement methods that ... Read More

How to use Function and BiFunction interfaces in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 06:37:00

2K+ Views

The Function interface is a pre-defined functional interface that can be used as an assignment target for a lambda expression or method reference. It takes a single parameter and returns result by calling the apply() method. While the BiFunction interface is also a pre-defined functional interface that takes two parameters and returns a result. It is similar ... Read More

How to use Consumer and BiConsumer interfaces in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 06:30:59

3K+ Views

A Consumer interface is a predefined functional interface that can be used when creating lambda expressions or method references. This interface represents an operation that accepts a single input parameter and doesn't return anything. It contains only one method named accept(). The BiConsumer interface is similar to a Consumer interface and accepts two input parameters and doesn’t return ... Read More

How to implement an instance method reference using a class name in Java?

raja

raja

Updated on 13-Jul-2020 05:40:25

667 Views

Method reference is a simplified form of the lambda expression. It can specify a class name or instance name followed by the method name. The "::" symbol can separate a method name from the name of an object or class.An instance method reference refers to an instance method of any class. In the below example, we can implement an ... Read More

How can we write Callable as a lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 05:32:03

5K+ Views

A Callable interface defined in java.util.concurrent package. An object of Callable returns a computed result done by a thread in contrast to a Runnable interface that can only run the thread. The Callable object returns Future object that provides methods to monitor the progress of a task executed by a thread. An object of the Future used ... Read More

What are the SAM Interfaces in Java?

raja

raja

Updated on 13-Jul-2020 05:26:06

4K+ Views

An interface having only one abstract method is known as a functional interface and also named as Single Abstract Method Interfaces (SAM Interfaces). One abstract method means that either a default method or an abstract method whose implementation is available by default is allowed. The instances of SAM interfaces are java.lang.Runnable, java.awt.event.ActionListener,  java.util.Comparator ... Read More

Differences between Method Reference and Constructor Reference in Java?

raja

raja

Updated on 11-Jul-2020 12:54:44

2K+ Views

A method reference is similar to lambda expression used to refer a method without invoking it while constructor reference used to refer to the constructor without instantiating the named class. A method reference requires a target type similar to lambda expressions. But instead of providing an implementation of a method, they refer to a method of an existing class or ... Read More

Advertisements