Linked Questions
13 questions linked to/from What is difference between Collection.stream().forEach() and Collection.forEach()?
15 votes
3 answers
21k views
What is the difference between .foreach and .stream().foreach? [duplicate]
This is a example: code A: files.forEach(f -> { //TODO }); and another code B may use on this way: files.stream().forEach(f -> { }); What is the difference between both, with stream() and ...
8 votes
1 answer
2k views
Difference between iterable.forEach() and iterable.stream().forEach() [duplicate]
It looks like I can call list.forEach(a -> a.stuff()) directly on my collection, instead of list.stream().forEach(a -> a.stuff()). When would I use one over the other (parallelStream() aside..)?
2 votes
2 answers
2k views
Pros and Cons of usage forEach and Stream [duplicate]
Starts from java 8 to iterate throug list I can use both: List list = new ArrayList(); 1. list.forEach(...) 2. list.stream().forEach(...) Is it any advantages of using second case? To convert list to ...
5 votes
2 answers
843 views
What is the difference between Java8 container `for each` and Stream `for each` [duplicate]
I know we can use List.foreach to traverse,and we can use List.stream.foreach to traverse too. I do not understand which is better to traverse in Java8.
-1 votes
4 answers
710 views
Sonar : Replace this lambda with a method reference. When should "stream()" be used? [duplicate]
I would like to know what is the difference between these two three pieces of code: underlyingConnectors.values().stream().forEach(connector -> connector.start()); underlyingConnectors.values()....
3 votes
0 answers
862 views
.forEach() vs .stream.forEach()? [duplicate]
I've been learning how to use streams and lambda expressions, and came across this question. What is the difference between: Arrays.asList(myDogs).forEach((d) -> {System.out.println(d.toString());...
0 votes
0 answers
62 views
What is the difference between stream and foreach when I want to process sequence of CompletetableFuture ? Following is the logic [duplicate]
List<Object> someList = getSomeList(); someList.stream().forEach( (callSomeCompletableFutureFunction) .thenCompose ( call another completableFutureFunction) ....
561 votes
8 answers
546k views
Java 8 Iterable.forEach() vs foreach loop
Which of the following is better practice in Java 8? Java 8: joins.forEach(join -> mIrc.join(mSession, join)); Java 7: for (String join : joins) { mIrc.join(mSession, join); } I have lots of ...
10 votes
3 answers
2k views
Should I use shared mutable variable update in Java 8 Streams
Just iterating below list & adding into another shared mutable list via java 8 streams. List<String> list1 = Arrays.asList("A1","A2","A3","A4","A5","A6","A7","A8","B1","B2","B3"); List<...
2 votes
3 answers
4k views
How to filter nested loops using Java 8 streams and filters?
I have two simple POJOs: public class Parent { String name; List<Child> children = new ArrayList<>(); void addChild(Integer age) { children.add(new Child(age)); } } public ...
1 vote
1 answer
4k views
Ways to map the list of objects to another list of objects
First of all, These classes are mock data classes. I have list of phones and i have to create a new list that has phone types only. For that, I have two options, If anyone can explain which option is ...
0 votes
2 answers
538 views
Cannot return List<T> using builder in Java
I have a save method that returns CommandDTO. // ... final MenuItem saved = menuItemRepository.save(menuItem); return CommandDTO.builder().uuid(saved.getUuid()).build(); Here is my CommandDTO: @...
-1 votes
1 answer
163 views
Can we throw two Exceptions by Streaming and mapping?
Actually I want to throw two exceptions as part of checking two conditions. But wondering how to throw these exceptions after streaming and mapping it. This is the code to be converted to Java-8 ...