Java 8 : Function
What is a Function?
This is a predefined functional interface like Predicate, present in java.util.function package. It has one abstract method called apply();
1 | interface Function<T,R> { |
Function example 1: to check the length of the string.
1 | package com.blogspot.ekumeedkiasha; |
Function Chaining example:
1 | package com.blogspot.ekumeedkiasha; |
Java 8 : Predicates
1 | package com.blogspot.ekumeedkiasha; |
Predicate Joining Example:
Interface predicate has three default methods.
1. and(Predicate p)
2. or(Predicate p)
3. negate()
find out all the even numbers which are greater than 5 in the given array.
1 | package com.blogspot.ekumeedkiasha; |
For equality predicate interface has isEqual(Object o) method which is static.
Example:
1 | package com.blogspot.ekumeedkiasha; |
Java 8 : Predicates
Java 8 comes with a concept of functional interface. An interface having only one abstract method and any number of default and static methods is called a functional interface.
A Predicate (boolean-valued function) of one argument which is present in java.util.function package. It is predefined functional interfaces that It has only one abstract method i.e, test().
1 2 | interface Predicate<T> { |
Predicate Example to check age is greater than 18 or not.
Step: -1
1 | public boolean test(Integer age) { |
Step -2
1 | public class PredicateExample { |
Predicate Example to check collection is empty or not
1 | package com.blogspot.ekumeedkiasha; |
Java 8 : Lambda with Thread Example
Hello Friends,
Thank you for visiting this blog. This is the continuation of my Java 8 video series tutorials which was published in youtube channel ekumeedhelp.
In this post, we will be learning about the use of Java 8 lambda expression in Thread.
Create Thread without using lambda
Example:- 1
Create Thread with Lambda Example
Example:- 2
Create Thread using Anonymous class
Example:- 3
Thank you for visiting this blog. This is the continuation of my Java 8 video series tutorials which was published in youtube channel ekumeedhelp.
In this post, we will be learning about the use of Java 8 lambda expression in Thread.
Create Thread without using lambda
Example:- 1
1 | //https://ekumeedkiasha.blogspot.com/ |
Create Thread with Lambda Example
Example:- 2
1 | //https://ekumeedkiasha.blogspot.com/ |
Example:- 3
1 | //https://ekumeedkiasha.blogspot.com/ |
Subscribe to:
Posts (Atom)