SlideShare a Scribd company logo
Concept of Stream API Java 1.8
Stream concept is introduced in java 1.8 and present in java.util.stream
package.It is used to process the object from collection or any group of objects
or data source. We can easily understand java stream concept by it's name
stream, In stream water flows from one water source to destination and we can
perform some operations like filtering, collecting etc on stream to get useful
water,Same in java stream concept we can think object flows from one object
source to destination by Stream pipelines (A stream pipeline is composed of a
stream source, zero or more intermediate operations, and a terminal
operation.)
We should be familiar with some concept before going to further in stream
concept and remember one thing streams don’t actually store elements; they
are computed on demand.
1> C.stream() - we are going to get an stream object where C is collection
object.
2>filter()- used to do filtering based on predicate(predicate is nothing but
boolean condition, basically it is a functional interface so it can be replaced by
lambda expression)
3> collect()- it is a terminal operation use to collect filtered or mapped data.
Example-
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(0);
arrayList.add(10);
arrayList.add(20);
arrayList.add(5);
arrayList.add(15);
arrayList.add(25);
System.out.println(arrayList);
output will be [0,10,20,5,15,25]. Now,we want to get a new ArrayList of
integer which contains only even integers from existing arrayList object. Here,
how we process collection object without stream concept
List<Integer> list = new ArrayList<Integer>();
for(Integer i:arrayList){
if(i%2 == 0)
list.add(i);
}
System.out.println(arrayList);
output will be [0,10,20]
with stream concept-
List<Integer> list =
arrayList.stream().filter(i->i%2==0).collect(Collectors.toList());
System.out.println(arrayList);
output will be [0,10,20].In collection if we perform bulk operation then highly
recommended to use stream concept.
some more useful method of stream concept-
4> map()- for every object if we want to perform some action and want some
result object then we use map method if we want to increase all the arrayList
data by 5 then we can use this function.
List<Integer> l = arrayList.stream().map(i-> i+5).collect(Collectors.toList());
it always take functional interface(interface which contains only one method)
so we can replace it by lambda expression.
5> count() - use to count how many objects are there in stream ( not in data
source).
long noOfEvenInteger = arrayList.stream().filter(i-> i%2!=0).count();
6> sorted() - use to perform sorting in ascending order.
List<Integer> l = arrayList.stream().sorted().collect(Collectors.toList()); return
an ascending order list.
for customization we go for comparator concept.comparator is also a
functional interface so we can replace it by lambda expression.
Comparator - it contains compare() method and we can replace it by lambda
expression compare(obj1, obj2)- return -ve if obj1 has to come before
obj2; return +ve if obj1 has to come after obj2; return 0 if both are
equal;
we perform sorting in desc order here, what we do inside compare method (i1,
i2)-> (i1<i2)?1:(i1 > i2)?-1:0 . We compare two object i1 and i2 if i1 is smaller
than i2 it means i1 has to come before i2, so it will return +ve else it check i1 is
bigger or not if yes it means i1 has to come after i2, so it will return -ve and if
both are equal then it will return 0;
List<Integer> list = arrayList.stream().sorted((i1,i2)->(i1, i2)-> (i1<i2)?1:(i1 >
i2)?-1:0).collect(Collectors.toList());
7> forEach() - for every element if we want to perform some functionality.
arrayList.stream().forEach(System.out::println);
it will print all object.We can call our own method also.
Consumer<Integer> fun = i->{System.out.println("square of"+i+"is = "+(i*i))};
arrayList.stream().forEach(fun);
8> toArray() - to convert stream of object into array.
Integer[] arr = arrayList.stream().toArray(Integer::new);
9> Stream.of(arr) - use to get stream from array or other group of data;
Stream s = stream.of(10,1,2,12,34);
s.forEach(System.out::println);

More Related Content

What's hot

Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
DrRajeshreeKhande
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
Syed Afaq Shah MACS CP
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181
Mahmoud Samir Fayed
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
Philip Schwarz
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
Philip Schwarz
 
Python array
Python arrayPython array
Python array
Arnab Chakraborty
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
Lifna C.S
 
Lec3
Lec3Lec3
Min priority queue
Min priority queueMin priority queue
Min priority queue
9854098540
 
Max priority queue
Max priority queueMax priority queue
Max priority queue
9854098540
 
Java8
Java8Java8
Knolx session
Knolx sessionKnolx session
Knolx session
Knoldus Inc.
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
Vasim Pathan
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
kalyanineve
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
mdfkhan625
 

What's hot (20)

Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
 
Lecture 6 - Arrays
Lecture 6 - ArraysLecture 6 - Arrays
Lecture 6 - Arrays
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181The Ring programming language version 1.5.2 book - Part 21 of 181
The Ring programming language version 1.5.2 book - Part 21 of 181
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Python array
Python arrayPython array
Python array
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Lec3
Lec3Lec3
Lec3
 
Min priority queue
Min priority queueMin priority queue
Min priority queue
 
Max priority queue
Max priority queueMax priority queue
Max priority queue
 
Java8
Java8Java8
Java8
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
Array properties
Array propertiesArray properties
Array properties
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
 

Similar to Concept of Stream API Java 1.8

Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
SoftNutx
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
veerendranath12
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
Jobaer Chowdhury
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
Urs Peter
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
IllllBikkySharmaIlll
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
Drishti Bhalla
 
List in java
List in javaList in java
List in java
nitin kumar
 
Java Foundations: Maps, Lambda and Stream API
Java Foundations: Maps, Lambda and Stream APIJava Foundations: Maps, Lambda and Stream API
Java Foundations: Maps, Lambda and Stream API
Svetlin Nakov
 
collections
collectionscollections
collections
javeed_mhd
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
Surendar Meesala
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 

Similar to Concept of Stream API Java 1.8 (20)

Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
Lec3
Lec3Lec3
Lec3
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Nature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptxNature Activities Binder _ by Slidesgo.pptx
Nature Activities Binder _ by Slidesgo.pptx
 
Collections
CollectionsCollections
Collections
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Lec2
Lec2Lec2
Lec2
 
07 java collection
07 java collection07 java collection
07 java collection
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
List in java
List in javaList in java
List in java
 
Java Foundations: Maps, Lambda and Stream API
Java Foundations: Maps, Lambda and Stream APIJava Foundations: Maps, Lambda and Stream API
Java Foundations: Maps, Lambda and Stream API
 
collections
collectionscollections
collections
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 

More from InnovationM

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
InnovationM
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
InnovationM
 
Mob x in react
Mob x in reactMob x in react
Mob x in react
InnovationM
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
InnovationM
 
Android 8 behavior changes
Android 8 behavior changesAndroid 8 behavior changes
Android 8 behavior changes
InnovationM
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architecture
InnovationM
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swift
InnovationM
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
InnovationM
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
InnovationM
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” up
InnovationM
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
InnovationM
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
InnovationM
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-Boot
InnovationM
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJS
InnovationM
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
InnovationM
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )
InnovationM
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
InnovationM
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?
InnovationM
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For Android
InnovationM
 
Retrofit Library In Android
Retrofit Library In AndroidRetrofit Library In Android
Retrofit Library In Android
InnovationM
 

More from InnovationM (20)

How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
Mob x in react
Mob x in reactMob x in react
Mob x in react
 
How to use geolocation in react native apps
How to use geolocation in react native appsHow to use geolocation in react native apps
How to use geolocation in react native apps
 
Android 8 behavior changes
Android 8 behavior changesAndroid 8 behavior changes
Android 8 behavior changes
 
Understanding of react fiber architecture
Understanding of react fiber architectureUnderstanding of react fiber architecture
Understanding of react fiber architecture
 
Automatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swiftAutomatic reference counting (arc) and memory management in swift
Automatic reference counting (arc) and memory management in swift
 
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
Firebase crashlytics integration in iOS swift (dSYM File Required Problem Res...
 
How prototype works in java script?
How prototype works in java script?How prototype works in java script?
How prototype works in java script?
 
React – Let’s “Hook” up
React – Let’s “Hook” upReact – Let’s “Hook” up
React – Let’s “Hook” up
 
Razorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS SwiftRazorpay Payment Gateway Integration In iOS Swift
Razorpay Payment Gateway Integration In iOS Swift
 
Paytm integration in swift
Paytm integration in swiftPaytm integration in swift
Paytm integration in swift
 
Line Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-BootLine Messaging API Integration with Spring-Boot
Line Messaging API Integration with Spring-Boot
 
Basic fundamental of ReactJS
Basic fundamental of ReactJSBasic fundamental of ReactJS
Basic fundamental of ReactJS
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )Integration of Highcharts with React ( JavaScript library )
Integration of Highcharts with React ( JavaScript library )
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?How to Make Each Round of Testing Count?
How to Make Each Round of Testing Count?
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For Android
 
Retrofit Library In Android
Retrofit Library In AndroidRetrofit Library In Android
Retrofit Library In Android
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

Concept of Stream API Java 1.8

  • 1. Concept of Stream API Java 1.8 Stream concept is introduced in java 1.8 and present in java.util.stream package.It is used to process the object from collection or any group of objects or data source. We can easily understand java stream concept by it's name stream, In stream water flows from one water source to destination and we can perform some operations like filtering, collecting etc on stream to get useful water,Same in java stream concept we can think object flows from one object source to destination by Stream pipelines (A stream pipeline is composed of a stream source, zero or more intermediate operations, and a terminal operation.) We should be familiar with some concept before going to further in stream concept and remember one thing streams don’t actually store elements; they are computed on demand. 1> C.stream() - we are going to get an stream object where C is collection object. 2>filter()- used to do filtering based on predicate(predicate is nothing but boolean condition, basically it is a functional interface so it can be replaced by lambda expression) 3> collect()- it is a terminal operation use to collect filtered or mapped data. Example- ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(0); arrayList.add(10); arrayList.add(20); arrayList.add(5); arrayList.add(15); arrayList.add(25); System.out.println(arrayList);
  • 2. output will be [0,10,20,5,15,25]. Now,we want to get a new ArrayList of integer which contains only even integers from existing arrayList object. Here, how we process collection object without stream concept List<Integer> list = new ArrayList<Integer>(); for(Integer i:arrayList){ if(i%2 == 0) list.add(i); } System.out.println(arrayList); output will be [0,10,20] with stream concept- List<Integer> list = arrayList.stream().filter(i->i%2==0).collect(Collectors.toList()); System.out.println(arrayList); output will be [0,10,20].In collection if we perform bulk operation then highly recommended to use stream concept. some more useful method of stream concept- 4> map()- for every object if we want to perform some action and want some result object then we use map method if we want to increase all the arrayList data by 5 then we can use this function. List<Integer> l = arrayList.stream().map(i-> i+5).collect(Collectors.toList()); it always take functional interface(interface which contains only one method) so we can replace it by lambda expression. 5> count() - use to count how many objects are there in stream ( not in data source). long noOfEvenInteger = arrayList.stream().filter(i-> i%2!=0).count(); 6> sorted() - use to perform sorting in ascending order. List<Integer> l = arrayList.stream().sorted().collect(Collectors.toList()); return an ascending order list. for customization we go for comparator concept.comparator is also a functional interface so we can replace it by lambda expression.
  • 3. Comparator - it contains compare() method and we can replace it by lambda expression compare(obj1, obj2)- return -ve if obj1 has to come before obj2; return +ve if obj1 has to come after obj2; return 0 if both are equal; we perform sorting in desc order here, what we do inside compare method (i1, i2)-> (i1<i2)?1:(i1 > i2)?-1:0 . We compare two object i1 and i2 if i1 is smaller than i2 it means i1 has to come before i2, so it will return +ve else it check i1 is bigger or not if yes it means i1 has to come after i2, so it will return -ve and if both are equal then it will return 0; List<Integer> list = arrayList.stream().sorted((i1,i2)->(i1, i2)-> (i1<i2)?1:(i1 > i2)?-1:0).collect(Collectors.toList()); 7> forEach() - for every element if we want to perform some functionality. arrayList.stream().forEach(System.out::println); it will print all object.We can call our own method also. Consumer<Integer> fun = i->{System.out.println("square of"+i+"is = "+(i*i))}; arrayList.stream().forEach(fun); 8> toArray() - to convert stream of object into array. Integer[] arr = arrayList.stream().toArray(Integer::new); 9> Stream.of(arr) - use to get stream from array or other group of data; Stream s = stream.of(10,1,2,12,34); s.forEach(System.out::println);