Honestly, I have never commented on a video before on youtube but for this I cannot hold my peace than to Thank you for this wonderful videos. You have my 5 stars already. I really really love this
The video explains the concept in more understandable form than any other articles in recent past. Yet I would like to know how Streams and the methods are internally working. Is Java really implementing some optimized logic better regular coding or compiler writing regular code internally on behalf us, just for reducing the redundant code?. IS Stream really faster than regular approach?
Hi Sir, I want to correct two things. your way of teaching is nice. 1. map-> It takes function as argument Returns a stream consisting of the results of applying the given function to the elements of this stream. 2. In this program there is no need of map(). we can do directly using filter only. employeeList.stream().filter(e->e.getSalary()>20000).forEach(e->System.out.println(e.getSalary())); Output- 30000 40000 50000 Kindly look into it.
no bro, foreach uses consumer class and accepts the stream and performs operation, it does not return anything if you check documentation of foreach its return type would be null, other hand map returns a stream, which we can do something like printing, or converting a list, in simple words foreach takes a stream and just performs the operation does not return anything (it uses concept of functional interface and lambda expression check in youtube ), but map takes a function as parameter and performs that function on the elements in the stream and returns a new stream.
you can create a List and then after you apply map or filter the result you can save to this list with collect(Collectors.toList()), it would be like this lets say you have employee class with name and ID , and you have a list of objects of type Employee, //creating employee class class Employee{ int Id; String name; Employee(int Id,String name){ this.Id=Id; this.name=name; } } //creating main class with filter implementation public class MapInStreamsPractice { public static void main(String[] args) { //creating list of employee class List employees = new ArrayList(); employees.add(new Employee(21,"rajesh")); employees.add(new Employee(22,"shiva")); employees.add(new Employee(23,"vignesh")); //filtering each employee whos id is greater than 20 using filter method. List employeeList=employees.stream().filter(employee -> employee.Id>20).collect(Collectors.toList()); //you can print employeelist and check for output } }
Hi Sir can ou help me out in this logic? Create Person class that contains first name, last name, and ID. - Create a getCommonLastNames() method with that takes List as a parameter. - The method should return a Map whereby the key is the common last name and the value is the list of firstnames of people that share the same last name. i can do this... Map Map8 = Person1.stream().collect(Collectors.toMap(Person::getFirstName, Person::getLastName)); Map Map8 = Person1.stream().filter(f->f.FirstName==f.LastName).collect(Collectors.toMap(Person::getFirstName, Person::getLastName));
Hi sir, after filtering based on Salary, i want to update the salary by increasing 10 percent and return complete employe objects, how can i achieve this
Honestly, I have never commented on a video before on youtube but for this I cannot hold my peace than to Thank you for this wonderful videos. You have my 5 stars already. I really really love this
Thanks
map(Function
11.24 - it seems ,map will take Function as parameter, not Consumer
forEach(Consumer
Fantastic Explanation in Java 8 i saw all udemy and youtubue channel this is one fantastic explanation and eazily understand once study.
Thanks
You are Awesome.....Best Teaching for each and every topic...Thank you so much
You are most welcome
The best so far
Last few minutes of video ,I think that you should have performed some operation inside map but you simple printed it ,but thank you
Great video. Thanks for uploading it. ❤
Glad you enjoyed it!
Thanks for this video. It's helpful.
You're welcome
The video explains the concept in more understandable form than any other articles in recent past. Yet I would like to know how Streams and the methods are internally working. Is Java really implementing some optimized logic better regular coding or compiler writing regular code internally on behalf us, just for reducing the redundant code?. IS Stream really faster than regular approach?
Hi Sir,
I want to correct two things. your way of teaching is nice.
1. map-> It takes function as argument Returns a stream consisting of the results of applying the given function to the elements of this stream.
2. In this program there is no need of map(). we can do directly using filter only.
employeeList.stream().filter(e->e.getSalary()>20000).forEach(e->System.out.println(e.getSalary()));
Output-
30000
40000
50000
Kindly look into it.
Hi
Actually sir wants to store in another list. So we should use map to store and print the list of salary
Thanks for another wonderful video!
Welcome
Excellent 👌
Thanks
Nice explanation sir
Thanks
Best tutorial always!
Thanks again!
Excellent explanation!
Glad it was helpful!
Question were very very basic pls try to add a bit complex Qs after 1,2 regular Qs. Because in interviews we were not asked this much basic QS
Thanks for this video. It's helpful. Is Map and Foreach methods are same?. Because I see both of them can be used to print the list objects
no u are wrong
map is taking function as a parameter and the return object of function is added to stream. at the end it will return that stream
no bro, foreach uses consumer class and accepts the stream and performs operation, it does not return anything if you check documentation of foreach its return type would be null, other hand map returns a stream, which we can do something like printing, or converting a list, in simple words foreach takes a stream and just performs the operation does not return anything (it uses concept of functional interface and lambda expression check in youtube ), but map takes a function as parameter and performs that function on the elements in the stream and returns a new stream.
Thank you Sir.
You are most welcome
Thank you
Welcome
Nice Content.
Thanks!
Is there video on Optional class java 8 feature ?
Everything is good sir
Bt one doubt
What if I want to save the modified employee list instead of list
you can create a List and then after you apply map or filter the result you can save to this list with collect(Collectors.toList()), it would be like this
lets say you have employee class with name and ID , and you have a list of objects of type Employee,
//creating employee class
class Employee{
int Id;
String name;
Employee(int Id,String name){
this.Id=Id;
this.name=name;
}
}
//creating main class with filter implementation
public class MapInStreamsPractice {
public static void main(String[] args) {
//creating list of employee class
List employees = new ArrayList();
employees.add(new Employee(21,"rajesh"));
employees.add(new Employee(22,"shiva"));
employees.add(new Employee(23,"vignesh"));
//filtering each employee whos id is greater than 20 using filter method.
List employeeList=employees.stream().filter(employee -> employee.Id>20).collect(Collectors.toList());
//you can print employeelist and check for output
}
}
We can add list in the collection
Thanks Sir... Please make videos on dot net.
Hi Sir can ou help me out in this logic?
Create Person class that contains first name, last name, and ID.
- Create a getCommonLastNames() method with that takes List as a parameter.
- The method should return a Map
whereby the key is the common last name and the value is the list of firstnames of people that share the same last name.
i can do this...
Map Map8 = Person1.stream().collect(Collectors.toMap(Person::getFirstName, Person::getLastName));
Map Map8 = Person1.stream().filter(f->f.FirstName==f.LastName).collect(Collectors.toMap(Person::getFirstName, Person::getLastName));
Send keys functionality not working in my appium program.how to send the data into text field
Hi sir, after filtering based on Salary, i want to update the salary by increasing 10 percent and return complete employe objects, how can i achieve this
employeesList.stream()
.filter(emp -> emp.salary > 25000)
.map(emp -> {
emp.salary = emp.salary + (emp.salary * 10) / 100;
return emp;
})
.forEach(t -> System.out.println(t));
employeesList.stream().filter(emp->emp.salary>50000 && emp.salary{
emp.salary += emp.salary*0.1;
return emp;
})
.forEach(System.out::println);