+ 7
Why use consumer and supplier?
Please, If anyone knows the advantage of the Consumer and the Supplier explain. I read a few websites about them in Java8 but I wasn't convinced why I should use this functions.
3 Respuestas
+ 11
No or yes
Lambada experssion remove boilerplate codes.
+ 10
Consumer Interface is a functional interface and this interface have a abstract accept method.
If you want to itrate list using forEach method than forEach method want Consumer interface
To print list item one by one.
In simple word forEach method aceept list item and consumer interface responcibal to print item one by one using this accept method.
thats all.
Here is internal implementaion (java 7)
v.forEach(new Consumer<Integer>(){
public void accept(Integer i){
System.out.println(i);
}
});
Using lambda expression (java 8)
v.forEach( i ->System.out.println(i));
+ 7
Sumit Programmer😎😎 thank you for your description. Does it affect the performance of the program?