Raja has Published 806 Answers

How to implement DoubleFunction using lambda expression in Java?

raja

raja

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

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

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

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

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

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

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

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

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

raja

raja

Updated on 13-Jul-2020 09:07:52

ToIntFunction is the built-in functional interface defined in java.util.function package. This functional interface expects an argument as input and produces an int-valued result. It can be used as an assignment target for a lambda expression or method reference. The ToIntFunction interface holds only one method, applyAsInt(). This method performs an operation on the given argument and ... Read More

How to reverse a string using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 09:03:02

A String is an object that represents a sequence of characters and immutable in Java. We can reverse a string entered by the user using the charAt() method of String class to extract characters from the string and append them in reverse order to reverse the entered string.In the below example, we need to ... Read More

How to serialize a lambda function in Java?

raja

raja

Updated on 13-Jul-2020 08:45:42

The Serialization is a process for writing the state of an object into a byte stream so that we can transfer it over the network. We can serialize a lambda expression if its target type and its captured arguments have serialized. However, like inner classes, the serialization of lambda expressions is strongly discouraged.In the below example, we can serialize and ... Read More

Advertisements