15690/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); }
The advantage comes into account when the operations can be executed in parallel.
The main advantage from my point of view is that the implementation of what is to be done within the loop can be defined without having to decide if it will be executed in parallel or sequential
If you want your loop to be executed in parallel you could simply write
joins.parallelStream().forEach(join -> mIrc.join(mSession, join));
You will have to write some extra code for thread handling etc.
Basically, there are two important differences between ...READ MORE
You can use break with a label for the ...READ MORE
Hi, there is no as such difference ...READ MORE
I think you are not alone who is ...READ MORE
As you might be knowing, all these ...READ MORE
You can either use the iterator directly ...READ MORE
To safely remove from a collection while ...READ MORE
You can use Java Runtime.exec() to run python script, ...READ MORE
First, find an XPath which will return ...READ MORE
See, both are used to retrieve something ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.