Linked Questions

15 votes
3 answers
21k views

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 ...
ming's user avatar
  • 333
8 votes
1 answer
2k views

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..)?
jlb's user avatar
  • 20.1k
2 votes
2 answers
2k views

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 ...
Shell Scott's user avatar
  • 1,939
5 votes
2 answers
843 views

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.
zzkyeee's user avatar
  • 75
-1 votes
4 answers
710 views

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()....
Muhamad Gafar's user avatar
3 votes
0 answers
862 views

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());...
zephos2014's user avatar
0 votes
0 answers
62 views

List<Object> someList = getSomeList(); someList.stream().forEach( (callSomeCompletableFutureFunction) .thenCompose ( call another completableFutureFunction) ....
Hiren's user avatar
  • 280
561 votes
8 answers
546k views

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 ...
nebkat's user avatar
  • 8,553
10 votes
3 answers
2k views

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<...
Thirunavukkarasu's user avatar
2 votes
3 answers
4k views

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 ...
Kamil Nękanowicz's user avatar
1 vote
1 answer
4k views

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 ...
user avatar
0 votes
2 answers
538 views

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: @...
user avatar
-1 votes
1 answer
163 views

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 ...
Jeeva D's user avatar
  • 374