Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 103 fix this the parts of the pipeline that follow the call Its worth noting that the stream methods dont really execute the processing rather they configure the various pipes and processing elements and this is why the position of Using parallel to run in parallel mode can sometimes cause the order of the items arriving at the collector to be altered by concurrency interleaving the parallel call is not significant unless its followed by a call to sequential which would be confusing but still not an error such a call merely overrides the efect of the call to parallel Because of these observations both options A and B are incorrect Having established that the code runs you must determine what it does The form of the stream appears ready to print out the sequence of A through Z that is all the capital letters in order with the sequence repeated a second time Certainly the stream creates these values internally One question is whether the letters show up in order or not Using parallel to run in parallel mode can sometimes cause the order of the items arriving at the collector to be altered by concurrency interleaving and that might call into question whether option C is correct In fact parallel mode isnt the same as unordered mode and in this case the letters should not be jumbled by this efect Superficially then it looks like you should expect a bunch of capital letters but closer inspection shows the real root of this question It turns out that the second and third arguments to the collect method are incorrectly formed The three argument collect method theres also a single argument overload requires that the second and third arguments work to mutate a bucket of intermediate incremental result data with additional input But the bucket that is collecting the result is always the first of the two arguments to the operation and the second argument is the data that should be merged into that bucket In this case the first argument is merged into the second which will guarantee that the final result is empty That might seem like a tricky question but this mistake is easy to make if youre unfamiliar with the requirements of the collect operation and its hard
You must have JavaScript enabled to view digital editions.