Programming Articles

Page 2300 of 2547

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

raja
raja
Updated on 15-Jul-2020 212 Views

IntToLongFunction is a built-in functional interface from java.util.function package. This functional interface accepts an int-valued parameter and produces a long-valued result. IntToLongFunction 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 IntToLongFunction { long applyAsLong(int value); }Example of Lambda Expressionimport java.util.function.IntToLongFunction; public class IntToLongFunctionLambdaTest { public static void main(String args[]) { IntToLongFunction getLong = intVal -> { // lambda expression long ...

Read More

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

raja
raja
Updated on 14-Jul-2020 268 Views

IntToDoubleFunction is a functional interface from java.util.function package. This functional interface accepts an int-valued argument and produces a double-valued result. IntToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().Syntax@FunctionalInterface interface IntToDoubleFunction { double applyAsDouble(int value); }Example of Lambda Expressionimport java.util.function.IntToDoubleFunction;; public class IntToDoubleLambdaTest { public static void main(String[] args) { IntToDoubleFunction getDouble = intVal -> { // lambda expression double ...

Read More

How to implement DoubleToIntFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 397 Views

DoubleToIntFunction is a functional interface defined in java.util.function package introduced in Java 8 version. This functional interface accepts a double-valued argument and produces an int-valued result. DoubleToIntFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsInt().Syntax@FunctionalInterface interface DoubleToIntFunction { int applyAsInt(double value) }Exampleimport java.util.function.DoubleToIntFunction; public class DoubleToIntFunctionTest { public static void main(String args[]) { DoubleToIntFunction test = doubleVal -> { // lambda expression ...

Read More

How to implement DoubleToLongFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 331 Views

DoubleToLongFunction is a built-in functional interface from java.util.function package introduced in Java 8. This functional interface accepts a double-valued parameter and produces a long-valued result. DoubleToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface public interface DoubleToLongFunction { long applyAsLong(double value) }Exampleimport java.util.function.DoubleToLongFunction; public class DoubleToLongFunctionTest { public static void main(String args[]) { double dbl = 30.1212; DoubleToLongFunction castToLong = (dblValue) -> (long) dblValue; // lambda expression ...

Read More

How to declare a variable within lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 2K+ Views

A lambda expression is a function that expects and accepts input parameters and produces output results. It is an instance of a functional interface and also known as a single abstract method interface (SAM interface) like Runnable, Comparator, Callable and etc. We can declare a variable as a final string[] array and able to access that array index within a lambda expression.Exampleimport java.util.*; public class LambdaTest { public static void main(String args[]) { final String[] country = {null}; List cities = new ArrayList(); ...

Read More

How to implement ToLongBiFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 297 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); }Exampleimport java.util.*; import java.util.function.ToLongBiFunction; public class ToLongBiFunctionTest { public static void main(String[] args) { ToLongBiFunction getMobileNum = (map, value) -> { // lambda ...

Read More

How to implement ToLongFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 331 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; public class ToLongFunctionTest { public static void main(String args[]) { List list = new ArrayList(); list.add("11"); list.add("22"); ...

Read More

How to implement ToIntBiFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 348 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); }Exampleimport java.util.function.ToIntBiFunction; public class ToIntBiFunctionTest { public static void main(String args[]) { ToIntBiFunction test = (t, u) -> t * u; System.out.println("The ...

Read More

How to implement ToDoubleBiFunction using lambda expression in Java?

raja
raja
Updated on 14-Jul-2020 366 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 {    double applyAsDouble(T t, U u); }Exampleimport java.util.function.ToDoubleBiFunction; public class ToDoubleBiFunctionTest {    public static void main(String args[]) {       ToDoubleBiFunction test = (t, u) -> t / u;   // lambda expression       System.out.println("The division of t and u is: " + test.applyAsDouble(50, ...

Read More

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

raja
raja
Updated on 14-Jul-2020 1K+ 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 key and value with the help of lambda expression.Example for sorting of Map using Keyimport java.util.*; import java.util.stream.*; public class MapSortUsingKeyTest { public static void main(String args[]) { ...

Read More
Showing 22991–23000 of 25,466 articles
Advertisements