Java 8 Streams | map() and reduce() Example | JavaTechie
HTML-код
- Опубликовано: 7 сен 2024
- This tutorial will guide you to understand java 8 stream api map-reduce concept with Realtime implementation
#javatechie #stream #java8
GitHub:
github.com/Jav...
Blogs:
/ javatechie
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community , you are free to use source code from above mentioned GitHub account
nice explanation with simple examples.
Very Nice content! Greetings from Brazil 🇧🇷
Glad to have viewers from Brazil
Thank you so much. I am finding your videos are the clearest I have seen on the subjects. It is truly a pleasure to learn from you.
Thanks qwarlock ☺️
The examples used are simple , crisp and. clear
i got out from the interview just because i could not tell the reduce method with map....Now i wont get out for this topic at least 😍
at the end, its just a QUALITY CONTENT
Thanks for the nice video sir.
I love the way of elocution.. Gohead..
Very informative video,thanks for creating it,,
As always you are excellent sir
Thanks for your clear explanation
I enjoy all your videos. Excellent work sir
Nice video sir
Thank you Java Techie 🙏🙏
Nicely explain video 👍
Thank you so much. Your explanation always easy to understandable.
Keep learning buddy thank you 😊
Your content fan thankyou
great vedio
nyc explanation
What a great tutorial
very helpful.
Wonderful
Nice explanation
Your content explanation always easy to understandable.Pls explain with explain on distributed transaction in micro services.
great
Well done buddy!
Thank you!
Thank you
What do you mean by more readable?
In the summation example using iterative approach is also much more readable and verbose also, while in streams if some complex operation is being performed, you cannot debug the intermediate state until terminal operation is performed.
Traditional approach can be understood by even grade 10 student if he has learnt any programming language, why do we call streams more readable?
Hello buddy why can't you debug stream operations? Also when I say readable it means we do method chaining in such a way that it can easily identify what function we are performing in sequence
int result = numbers
.stream()
.reduce(0, (previousReturnedValue, element) -> previousReturnedValue + element);
excelent!
subcriber from ph
Thanks basant wlc back..
Muchas gracias
Can you please help out for small question:
Q) How can i get top 3 longest words in a given string using java 8
Map while Customer Object contains two filed Type and coount .type=I,count=10 ,type=o,count=20 .I want to display another map which contains Map = .eg.Map,MAP and so on. plz help
Not clear please elaborate it
Example : input : { a, b, k, {A, c, G,H,p}}
output : {a, b, k, {c,p}} . How to write stream fn for this. Expection is to remove capital letter from list.
Sir, we usually don't use getters seters explicitly mentioned right, like we go for lombok, if we have to have null check in getter methods , we can eliminate oly getter generation from lombok and have optional null check ? Or is there any way we have optimized way to do this?
Lombok is not recommended in prod environment
@@Javatechie thanks sir, i wasn't aware of this. Good to know this , will try to know the reason for it to have concrete details
List names = Arrays.asList("mike", "java", "adam", "ram"); here what output i will be expect for longest string?
Excellent , i believe it will print all since all words having 4 character
@@Javatechie yeah ,but it is not possible with reduce method because it will give single output,so what are we do in such situations?.. also your content is lot of helpful for beginners 🙏
We can use something like this
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
List stringList = Arrays.asList("Mike", "java");
int maxLength = stringList.stream()
.map(String::length)
.max(Integer::compare)
.orElse(0);
stringList.stream()
.filter(str -> str.length() == maxLength)
.forEach(str -> System.out.println("Longest string: " + str));
}
}
Nicely explained!!!
int arr1[] ={1,2,3,4,5}; when you define array as like this instead of Arrays.asList(1,2,3,4,5) how we can achieve iit ?
Pass this as Stream.of()
Can you please tell me how to find particular char or non-repeating in the string like ThatForThats I have to find ''F" in this
Hi ,
Any particular reason for having .map(employee -> employee.getSalary()) step in below example ?
double sumSalary = EmployeeDatabase.getEmployees().stream()
.filter(employee -> employee.getGrade().equalsIgnoreCase("A"))
.map(employee -> employee.getSalary())
.mapToDouble(i -> i)
.sum();
We could also do it as :
EmployeeDatabase.getEmployees().stream()
.filter(employee -> employee.getGrade().equalsIgnoreCase("A"))
.mapToDouble(employee->employee.getSalary())
.sum();
Yes you are correct we can do that
Hi Grate Techie ,could please upload rest api and Hibernate Jpa videos..🙏
It's already there please go to my channel and on right top corner you can see search tab
Just search with key which you want
Why isn't (a,b) -> a+b a bifunction since we have 2 parameters a and b?
Why we have to use .get() method
Hi,what is the use of identity in reduce can you explain.You have used 0 in sum and 1 in multiplication.
Identity is just initial value .
If you observed in iterative approach I took one variable i.e sum=0
That is nothing your identity
@@Javatechie Thanks for the explanation.
17:00 can we use 2 filters, one to get grade and 2nd one to get salary?
Yes you can but why can't we add both conditions in a single filter
@@Javatechie I tried but getting conversion error, let me try both conditions in one filter itself
hello Sir,
was very clear with the explanations, so the doubt is last 2 calculations using sum and average they did not use reduce function. Hence can they still be called as reductions?
Like every terminator operations like max,min,count etc are called reductions?
Yes they come under reduction
Does stream does parallel operation by default or we need to call parallel stream
No reduction method used parallel execution.
We must need to use parallel stream for parallisim
Can you please make vedio on Intellij tricks tips
What is use of map when we can directly use mapToDouble
Nice do you have interview series
Not started yet
how i->i means it an integer?
Can you please explain this...?
Bro u have any videos related to method reference
Sir I want file merging using mapreduce in Java coding
sounds quality is not very good
Please try increasing your system volume once and let me know if still clarity is not good