Raja has Published 760 Articles

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

raja

raja

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

525 Views

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

3K+ Views

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

615 Views

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

How to use IntStream in lambdas and method references in Java?

raja

raja

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

5K+ Views

An IntStream interface extends the BaseStream interface in Java 8. It is a sequence of primitive int-value elements and a specialized stream for manipulating int values. We can also use the IntStream interface to iterate the elements of a collection in lambda expressions and method references.Syntaxpublic interface IntStream extends BaseStreamExampleimport java.util.stream.IntStream; public class StringToIntegerStreamTest { ... Read More

How to use IntSupplier in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 08:41:18

581 Views

An IntSupplier is a functional interface defined in "java.util.function" package. This interface represents an operation that takes without arguments and returns the result of int type. IntSupplier interface has only one method, getAsInt() and returns a result. This functional interface can be used as an assignment target for lambda expressions or method references.Syntax@FunctionalInterface public interface IntSupplier {   ... Read More

How to use BooleanSupplier in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 08:34:39

2K+ Views

BooleanSupplier is a functional interface defined in the "java.util.function" package. This interface can be used as an assignment target for a lambda expression or method reference. BooleanSupplier interface has only one method getAsBoolean() and returns a boolean result, true or false.Syntax@FunctionalInterface public interface BooleanSupplier {    boolean getBoolean(); }Exampleimport java.util.function.BooleanSupplier; public class BooleanSupplierLambdaTest {   ... Read More

How to use FileFilter interface in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 08:30:13

571 Views

A FileFilter is a functional interface from the "java.io" package. It can be used as the assignment target for a lambda expression or method reference. An instance of the FileFilter interface passed to the listFiles() method of the File class. FileFilter interface having one abstract method accept() and it tests whether or not the specified abstract pathname has ... Read More

How to implement PropertyChangeListener using lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 08:13:49

4K+ Views

A PropertyChangeListener is a functional interface from java.beans package. It has one abstract method propertyChange() and gets called when a bound property is changed. This method takes a PropertyChangeEvent argument that has details about an event source and the property that has changed. A PropertyChangeSupport can be used by beans that support bound properties. It can ... Read More

How to iterate the contents of a collection using forEach() in Java?

raja

raja

Updated on 13-Jul-2020 08:06:06

264 Views

Lambda expression is the anonymous representation of a function descriptor of a functional interface. As we know that all collection interfaces like List, Set and Queue use an Iterable as their super interface. Since Java 8, an Iterable interface introduces a new method called forEach(). This method performs an action on the contents of Iterable in the order ... Read More

How to use UnaryOperator interface in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 08:00:30

889 Views

UnaryOperator is a functional interface that extends the Function interface. It represents an operation that accepts a parameter and returns a result of the same type as its input parameter. The apply() method from Function interface and default methods: andThen() and compose() are inherited from the UnaryOperator interface. A lambda expression and method reference can use UnaryOperator objects as ... Read More

Advertisements