Java Reference
In-Depth Information
Collection
The removeIf method can be used to remove all elements in a collection that match a predicate.
Note that this is different than the filter method included in the Streams API. The filter method
in the Streams API produces a new stream; it doesn't mutate the current stream or source.
List
The replaceAll method replaces each element in a List with the result of applying a given
operator to it. It's similar to the map method in a stream, but it mutates the elements of the List.
In contrast, the map method produces new elements.
For example, the following code will print [2, 4, 6, 8, 10] because the List is modified in place:
B.1.2. The Collections class
The Collections class has been around for a long time to operate on or return collections. It now
includes additional methods to return unmodifiable, synchronized, checked, and empty
NavigableMap and NavigableSet. In addition, it includes the method checkedQueue, which
returns a view of Queue that's extended with dynamic type checking.
B.1.3. Comparator
The Comparator interface now includes default and static methods. You used the
Comparator.comparing static method in chapter 3 to return a Comparator object given a
function that extracts the sorting key.
New instance methods include the following:
reversed —Returns a Comparator with the reverse ordering of the current Comparator .
thenComparing —Returns a Comparator that uses another Comparator when two objects are
equal.
thenComparingInt , thenComparingDouble , thenComparingLong —Work like the
thenComparing method but take a function specialized for primitive types (respectively,
ToIntFunction , ToDoubleFunction , and ToLongFunction ).
 
Search WWH ::




Custom Search