I'm reading OCP study guide (OCP_ Oracle Certified Professional Java SE 8 Programmer II Study Guide), in chapter 7, in a part talking about Using the One-Argument collect() Method, it is said that in order for reduction to be performed effeciently these requirments need to be fulfilled :
■■ The stream is parallel.
■■ The parameter of the collect operation has the Collector.Characteristics.CONCURRENT characteristic.
■■ Either the stream is unordered, or the collector has the characteristic Collector.Characteristics.UNORDERED.
So I wonder how to verify if a data structure fulfill the last 2 rules, for example I tried for the ConcurrentHashMap that is said to fulfill them but I didn't find any thing
The data structure doesn't fulfill the second requirement, the collector does. You can check the Collector.characteristics() method for the CONCURRENT and the UNORDERED characteristics.
Usually you create a stream from a data source yourself, and you already know if the data source has an intrinsic order or not. Lists are ordered. Sets are unordered, except if they're a subtype of SortedSet.
Stephan van Hulst wrote:. . . Lists are ordered. . . . .
. . . but it is awkward to make parallel Streams from some Lists. In order to get elements 1000...2000exc from a linked list, you have to iterate it to elements 1000 and 1999, but in the case of an array list it is very easy to find those indices with the get(int) method. So parallel Streams created from an array list tend to give much faster performance than those created from a linked list.
Does that sort of question feature in the OCP exam?
Only if you implement the stream by accessing the elements using the get() method. In reality, the stream is likely implemented with a Spliterator, which is precisely designed to solve these problems efficiently.