java 8 stream API tutorial

Before starting Java Stream API let’s look why it was required. Suppose we want to iterate over a list of strings and want to count strings with length less than 5. package com.w3schools; import java.util.ArrayList; import java.util.List; public class Test{ public static void main(String[] args) { List names = new ArrayList(); names.add(“Jai”); names.add(“Mahesh”); names.add(“Ajay”); names.add(“Hemant”); … Read more

Java 8 Interface Changes default method and static method

Why default method? For example we have an interface which has multiple methods, and multiple classes are implementing this interface. One of the method implementation can be common across the class. We can make that method as a default method, so that the implementation is common for all classes. Second scenario where we have already … Read more

Java 8 Method References

Java 8 introduced a new feature “Method Reference” which is used to refer the methods of functional interfaces. It is a shorthand notation of a lambda expression to call a method. We can replace lambda expression with method reference (:: operator) to separate the class or object from the method name. Types of method references … Read more

java 8 lambda expression filter on a list

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; import java.util.ArrayList; … Read more

java 8 lambda expression comparator

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; import java.util.ArrayList; … Read more

java 8 lambda expression creating thread

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; public class … Read more

java 8 lambda expression multiple statements

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; @FunctionalInterface interface … Read more

Java 8 lambda expression foreach loop

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; import java.util.ArrayList; … Read more

Java 8 lambda expression multiple parameters

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; @FunctionalInterface interface … Read more

Java 8 lambda expression hello world

Lambda expression is used to provide the implementation of functional interface. Java Lambda Expression Syntax (argument-list) -> {function-body} Where: Argument-list: It can be empty or non-empty as well. Arrow notation/lambda notation: It is used to link arguments-list and body of expression. Function-body: It contains expressions and statements for lambda expression. Example package com.w3schools; @FunctionalInterface interface … Read more