Java Reference
In-Depth Information
Note that there are primitive specializations for int, long, and double for each reduce operation
(for example, reduceValuesToInt, reduceKeysToLong, and so on).
Counting
The ConcurrentHashMap class provides a new method called mappingCount, which returns the
number of mappings in the map as a long. It should be used instead of the method size, which
returns an int. This is because the number of mappings may not fit in an int.
Set views
The ConcurrentHashMap class provides a new method called keySet that returns a view of the
ConcurrentHashMap as a Set (changes to the map are reflected in the Set and vice versa). You
can also create a Set backed by a ConcurrentHashMap using the new static method newKeySet.
B.3. Arrays
The Arrays class provides various static methods to manipulate arrays. It now includes four new
methods (which have primitive specialized overloaded variants).
B.3.1. Using parallelSort
The parallelSort method sorts the specified array in parallel, using a natural order, or using an
extra Comparator for an array of objects.
B.3.2. Using setAll and parallelSetAll
The setAll and parallelSetAll methods set all elements of the specified array, respectively
sequentially or in parallel, using the provided function to compute each element. The function
receives the element index and returns a value for that index. Because parallelSetAll is executed
in parallel, the function must be side-effect free, as explained in chapters 7 and 13 .
As an example, you can use the method setAll to produce an array with the values 0, 2, 4, 6, ...:
int[] evenNumbers = new int[10];
Arrays.setAll(evenNumbers, i -> i * 2);
 
Search WWH ::




Custom Search