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 { public static void main(String[] args) { String str = "Tutorials Point"; IntStream stream = str.chars(); stream.forEach(element -> System.out.println(((char)element))); // using lambda expression } }OutputT u t o r i a l s P o i n tExampleimport java.util.*; ... Read More
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 { int getAsInt(); }Exampleimport java.util.function.IntSupplier; public class IntSupplierTest { public static void main(String[] args) { IntSupplier intSupplier1 = () -> Integer.MAX_VALUE; // lamba expression System.out.println("The maximum value of an Integer is: " + intSupplier1.getAsInt()); IntSupplier intSupplier2 = () -> ... Read More
Here we will see how to design timer in C++ using a system call. We will not use any graphics or animations. Here timer means the stopwatch, that is up-counting the time. The used system calls are −sleep(n) − This will help the program to sleep for n number of secondssystem() − This is used to execute the system command by passing command as an argument to this function.Example Live Demo#include #include #include #include using namespace std; int hrs = 0; int mins = 0; int sec = 0; void showClk() { system("cls"); cout
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 { public static void main(String[] args) { BooleanSupplier Obj1 = () -> true; BooleanSupplier Obj2 = () -> 5 < 50; // lambda expression BooleanSupplier Obj3 = () -> "tutorialspoint.com".equals("tutorix.com"); System.out.println("Result of Obj1: " + Obj1.getAsBoolean()); ... Read More
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 included in a pathname list.Syntax@FunctionalInterface public interface FileFilterExampleimport java.io.File; import java.io.FileFilter; public class FileFilterTest { public static void main(String[] args) { File dir = new File("C:/Program Files/Java/jdk1.8.0_211"); File[] subDir = dir.listFiles((file) -> { // lambda expression ... Read More
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 manage a list of listeners and dispatches property change events. The PropertyChangeListener's implementer does the role of an Observer and bean wrapping the PropertyChangeSupport is Observable.Syntaxvoid propertyChange(PropertyChangeEvent evt)Exampleimport java.beans.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class PropertyChangeListenerLambdaTest { public static void main(String [] args) { ... Read More
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 elements that occur when iterating until all elements have processed.Syntaxvoid forEach(Consumer
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 their target.Syntax@FunctionalInterface public interface UnaryOperator extends FunctionExample-1import java.util.function.UnaryOperator; public class UnaryOperatorTest1 { public static void main(String[] args) { UnaryOperator operator = t -> t * 2; // lambda expression System.out.println(operator.apply(5)); System.out.println(operator.apply(7)); System.out.println(operator.apply(12)); } }Output10 ... Read More
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 returns a BinaryOperator that returns the greater of two elements according to a specified Comparator while the maxBy() method returns a BinaryOperator that returns the lesser of two elements according to a specified Comparator.Syntax@FunctionalInterface public interface BinaryOperator extends BiFunctionExampleimport java.util.function.BinaryOperator; public class BinaryOperatorTest { public static void main(String[] args) { BinaryOperator ... Read More
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. The get() method only returns a value and doesn't accept any argument, so a lambda expression having an empty argument part.Exampleimport java.util.*; import java.util.function.*; public class SupplierTest { public static void main(String args[]) { Supplier supplier1 = () -> "TutorialsPoint"; // lambda expression System.out.println(supplier1.get()); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP