@java2web #java #StreamAPI #kingBommTech
⚡⚡Stream API:🔥🔥
Introduced in Java 8
The Stream API is used to process collections of objects. A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result.
The features of Java stream are –
⭐⭐A stream is not a data structure instead it takes input from the Collections, Arrays or I/O channels.
⭐⭐Streams don’t change the original data structure, they only provide the result as per the pipelined methods.
⭐⭐Each intermediate operation is lazily executed and returns a stream as a result, hence various intermediate operations can be pipelined. Terminal operations mark the end of the stream and return the result.
Different Operations On Streams-
Two Operations
⭐⭐Intermediate Operations:
⭐⭐Terminal Operations:
Intermediate Operations:
👉map(): The map method is used to returns a stream consisting of the results of applying the given function to the elements of this stream.
List number = Arrays.asList(2,3,4,5);
List square = number.stream().map(x-x*x).collect(Collectors.toList());
filter(): The filter method is used to select elements as per the Predicate passed as argument.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().filter(s-s.startsWith("S")).collect(Collectors.toList());
sorted(): The sorted method is used to sort the stream.
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().sorted().collect(Collectors.toList());
Terminal Operations:
collect(): The collect method is used to return the result of the intermediate operations performed on the stream.
List number = Arrays.asList(2,3,4,5,3);
Set square = number.stream().map(x-x*x).collect(Collectors.toSet());
forEach(): The forEach method is used to iterate through every element of the stream.
List number = Arrays.asList(2,3,4,5);
number.stream().map(x-x*x).forEach(y-System.out.println(y));
reduce(): The reduce method is used to reduce the elements of a stream to a single value.
The reduce method takes a BinaryOperator as a parameter.
List number = Arrays.asList(2,3,4,5);
int even = number.stream().filter(x-x%2==0).reduce(0,(ans,i)- ans+i);
🌟🌟Share, Support, Subscribe!!!🔥🔥
Another Application with source Code:
⭐⭐ Food Delivery Application Project 🔥 :
• Online Food Delivery Application project u...
⭐⭐ Customer Service Disk Project 🔥:
• Customer Service Desk project in #java #se...
⭐⭐ Online Quiz Application Project 🔥 :
• Online Quiz Application project using #Jav...
⭐⭐ Ngo Font-End Web Designing Project 🔥 :
• Making NGO Front-End web designing using #...
⭐⭐ Online Banking Application Project 🔥 :
• Banking application using java | Bank Mana...
⭐⭐ Online Pharmacy Application Project 🔥 :
• Online Pharmacy Application project using ...
👉Angular JS Complete Course total Free 🔥 :
• Angular JS 🔥
Follow Me On Social Media
Twitter► / kingbommtech
Instagram► / kingbomm54
Email ► [email protected]
Share, Support, Subscribe!!!