Raja has Published 806 Answers

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

raja

raja

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

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

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

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

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

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

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

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

How to use BinaryOperator interface in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 07:29:22

BinaryOperator is one of a functional interface from java.util.function package and having exactly one abstract method. A lambda expression or method reference uses BinaryOperator objects as their target. BinaryOperator interface represents a function that takes one argument of type T and returns a value of the same type.BinaryOperator Interface contains two static methods, minBy() and maxBy(). The minBy() method ... Read More

How to use Supplier interface in lambda expression in Java?

raja

raja

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

A Supplier interface is a pre-defined interface that represents the supplier of results. It is instantiated using lambda expression or method reference or default constructor. The functional method of a Supplier interface is the get() method. This interface belongs to java.util.function package.Syntax@FunctionalInterface public interface SupplierIn the below program, we can use the Supplier interface in a lambda expression. ... Read More

How to use Predicate and BiPredicate in lambda expression in Java?

raja

raja

Updated on 13-Jul-2020 07:18:22

A Predicate interface defined in java.util.function package. It represents a boolean-valued function with one argument. It is kind of a functional interface whose functional method is the test(). BiPredicate interface is similar to the Predicate interface with two arguments. It can be used as an assignment target for a lambda expression.Syntax for Predicate@FunctionalInterface public interface PredicateExampleimport java.util.*; import java.util.function.*; ... Read More

Previous 1 ... 3 4 5 6 7 8 9 ... 81 Next
Advertisements