Raja has Published 760 Articles

How to implement ToDoubleFunction using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 12:10:26

605 Views

ToDoubleFunction is a functional interface defined in java.util.function package. This functional interface expects a parameter as input and produces a double-valued result. It is used as an assignment target for a lambda expression or method reference. ToDoubleFunction interface contains only one abstract method, applyAsDouble().Syntax@FunctionalInterface public interface ToDoubleFunction {    double applyAsDouble(T value); }Example-1import java.util.function.ToDoubleFunction; ... Read More

How to implement the Runnable interface using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 12:03:19

14K+ Views

The Runnable interface is a functional interface defined in java.lang package. This interface contains a single abstract method, run() with no arguments. When an object of a class implementing this interface used to create a thread, then run() method has invoked in a thread that executes separately.Syntax@FunctionalInterface public interface Runnable {  void run(); ... Read More

How to implement JavaFX event handling using lambda in Java?

raja

raja

Updated on 13-Jul-2020 11:54:58

3K+ Views

JavaFX Button class provides the setOnAction() method that can be used to set an action for the button click event. An EventHandler is a functional interface and holds only one method is the handle() method.Syntax@FunctionalInterface public interface EventHandler extends EventListenerIn the below example, we can able to implement event handling of JavaFX ... Read More

How to implement DoubleFunction using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 11:44:48

276 Views

The DoubleFunction is a built-in functional interface defined in java.util.function package. This interface accepts one double-valued parameter as input and returns a value of type R. As this is a functional interface, it can be used as an assignment target for a lambda expression or method reference. DoubleFunction interface having only one abstract method, ... Read More

How to generate prime numbers using lambda expression in Java?

raja

raja

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

2K+ Views

A prime number is a number that is greater than 1 and divided by 1 or itself only. It other words, it can't be divided by other numbers than itself or 1. The generation of prime numbers is 2, 3, 5, 7, 11, 13, 17 and etc.In the below example, we can generate the prime numbers with the ... Read More

How to implement IntFunction with lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 09:25:13

362 Views

IntFunction interface is a functional interface in Java 8 and defined in java.util.function package. This interface accepts an int-valued parameter as input and returns a value of type R. IntFunction interface can be used as an assignment target for a lambda expression or method reference and holds only one abstract method, apply().Syntax@FunctionalInterface public interface IntFunction {    R ... Read More

How to implement the Fibonacci series using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 09:24:29

3K+ Views

The Fibonacci is a sequence of numbers in which every number after the first two numbers is the sum of the two preceding numbers like 0, 1, 1, 2, 3, 5, 8, 13, 21 and so on. The sequence of Fibonacci numbers defined by using "F(n)=F(n-1)+F(n-2)".In the below example, we can implement ... Read More

How to sort a list using Comparator with method reference in Java 8?

raja

raja

Updated on 13-Jul-2020 09:23:06

1K+ Views

Java 8 introduced changes in the Comparator interface that allows us to compare two objects. These changes help us to create comparators more easily. The first important method added is the comparing() method. This method receives as a parameter Function that determines the value to be compared and creates Comparator. Another important ... Read More

How to populate a Map using a lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 09:11:10

2K+ Views

A Map is a collection object that maps keys to values in Java. The data can be stored in key/value pairs and each key is unique. These key/value pairs are also called map entries.In the below example, we can populate a Map using a lambda expression. We have passed Character and Runnable arguments to Map object and ... Read More

How to implement the ObjIntConsumer interface using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 09:09:29

226 Views

The ObjIntConsumer interface is a kind of functional interface and defined in java.util.function package. This functional interface expects an object-valued and int-valued argument as input and does not produce any output. It holds only one functional method, accept(Object, int).Syntax@FunctionalInterface    public interface ObjIntConsumer {       void accept(T t, int value) }In the ... Read More

Advertisements