Raja has Published 806 Answers

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

raja

raja

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

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

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

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

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

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

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

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

How to implement reference to an instance method of a particular object in Java?

raja

raja

Updated on 11-Jul-2020 12:53:39

Method reference is a simplified form of a lambda expression that can execute one method. It can be described using "::" symbol. A reference to the instance method of a particular object refers to a non-static method that is bound to a receiver.SyntaxObjectReference::instanceMethodNameExample - 1import java.util.*; public class InstanceMethodReferenceTest1 {   ... Read More

What are the rules for formal parameters in a lambda expression in Java?

raja

raja

Updated on 11-Jul-2020 12:50:17

A lambda expression is similar to a method that has an argument, body, and return type. It can also be called an anonymous function (method without a name). We need to follow some rules while using formal parameters in a lambda expression.If the abstract method of functional interface is a zero-argument method, then the ... Read More

What are the rules for the body of lambda expression in Java?

raja

raja

Updated on 11-Jul-2020 12:48:49

A lambda expression is an anonymous function (nameless function) that has passed as an argument to another function. We need to follow some rules while using the body of a lambda expression.Rules for the body of a lambda expressionThe body of the lambda expression can be either a single expression or more statements.If we are using ... Read More

Previous 1 ... 4 5 6 7 8 9 10 ... 81 Next
Advertisements