Raja has Published 760 Articles

How to implement ToLongBiFunction using lambda expression in Java?

raja

raja

Updated on 14-Jul-2020 13:50:14

134 Views

ToLongBiFunction is a in-built functional interface from java.util.function package. This functional interface accepts two reference type parameters as input and produces a long-valued result. ToLongBiFunction interface can be used as an assignment target for a lambda expression or method reference and contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface ToLongBiFunction {  long applyAsLong(T t, U u); ... Read More

How to implement ToLongFunction using lambda expression in Java?

raja

raja

Updated on 14-Jul-2020 13:45:09

173 Views

ToLongFunction is a functional interface defined in java.util.function package. This functional interface accepts a reference type as input and produces a long-valued result. ToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface ToLongFunction {    long applyAsLong(T value); }Exampleimport java.util.*; import java.util.function.ToLongFunction; ... Read More

How to implement ToIntBiFunction using lambda expression in Java?

raja

raja

Updated on 14-Jul-2020 13:40:19

171 Views

ToIntBiFunction is a built-in functional interface from java.util.function package. This interface accepts two parameters as input and produces an int-valued result. ToIntBiFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt() and doesn't contain any default or static methods.Syntax@FunctionalInterface interface ToIntBiFunction {    int applyAsInt(T t, U u); ... Read More

How to implement ToDoubleBiFunction using lambda expression in Java?

raja

raja

Updated on 14-Jul-2020 13:39:07

187 Views

ToDoubleBiFunction is a functional interface defined in java.util.function package. This functional interface accepts two parameters as input and produces a double-valued result. ToDoubleBiFunction interface can be used as an assignment target for a lambda expression or method reference. This interface contains only one abstract method: applyAsDouble() and doesn't contain any default or static methods.Syntax@FunctionalInterface interface ToDoubleBiFunction { ... Read More

How can we sort a Map by both key and value using lambda in Java?

raja

raja

Updated on 14-Jul-2020 13:30:27

746 Views

A Map interface implements the Collection interface that provides the functionality of the map data structure. A Map doesn't contain any duplicate keys and each key is associated with a single value. We can able to access and modify values using the keys associated with them.In the below two examples, we can able to sort a Map by both ... Read More

How to implement LongUnaryOperator using lambda in Java?

raja

raja

Updated on 14-Jul-2020 13:27:20

131 Views

LongUnaryOperator is a functional interface from java.util.function package. This functional interface accepts a single long-valued operand and produces a long-valued result. LongUnaryOperator interface can be used as an assignment target for lambda expression and method reference. It contains one abstract method: applyAsLong(), one static method: identity() and two default methods: andThen() and compose().Syntax@FunctionalInterface public interface LongUnaryOperator  long ... Read More

How to access variables from enclosing class using lambda in Java?

raja

raja

Updated on 14-Jul-2020 13:00:28

619 Views

The variables defined by the enclosing scope of a lambda expression can be accessible within the lambda expression. A lambda expression can access to both instance, static variables and methods defined by the enclosing class. It has also access to "this" variable (both implicitly and explicitly) that can be an instance of enclosing class. The ... Read More

How to create a thread using method reference in Java?

raja

raja

Updated on 14-Jul-2020 12:54:42

544 Views

Method reference is one of a way in a lambda expression to refer a method without executing it. In the body part of a lambda expression, we can call another method if they are compatible with a functional interface. We can also capture "this" and "super" keywords in method references.In the below two examples, ... Read More

How to implement DoubleUnaryOperator using lambda and method reference in Java?

raja

raja

Updated on 14-Jul-2020 12:48:28

172 Views

DoubleUnaryOperator is a functional interface defined in java.util.function package. This functional interface expects a parameter of type double as input but produces the output of the same type. DoubleUnaryOperator interface can be used as an assignment target for lambda expression and method reference. This interface contains one abstract method: applyAsDouble(), one static method: identity() and two default methods: ... Read More

How to implement LongSupplier using lambda and method reference in Java?

raja

raja

Updated on 14-Jul-2020 12:25:24

287 Views

LongSupplier is a built-in functional interface from java.util.function package. This interface doesn’t expect any input but produces a long-valued output. Since LongSupplier is a functional interface, it can be used as an assignment target for lambda expression and method reference and contains only one abstract method: getAsLong().Syntax@FunctionalInterface public interface LongSupplier {  long getAsLong(); }Example of Lambda Expressionimport java.util.function.LongSupplier; ... Read More

Advertisements