Java Reference
In-Depth Information
Table 3-2. ( continued )
Operation
Description
groupBy
Iterates over the collection and, for each element, evaluates the keySelector and
elementSelector functions, if present. The keySelector and the elementSelector
select a key and a destination element, respectively, from the source elements. If no
elementSelector is specified, elements of the collection become the destination
elements. The destination elements with the same key value are grouped in a Grouping ,
which is then yielded.
The groupings are yielded in the order in which their key values first occurred in the
original collection, and destination elements within a grouping are ordered by their
occurrences in the source elements.
A comparator can be used for comparison of the key values.
Example: employees.groupBy(p->p.position, p->p.salary)
distinct
Iterates over the source elements, yielding each element that has not previously been
yielded.
A comparator can be used to compare the elements.
Example: employees.distinct()
union
Iterates over the elements of the source and second collections, in that order. Each
element that has not yet been yielded is returned.
A comparator can be used to compare the elements.
Example: [1,3,5,7,9].union([2,4,6,8,10])
intersect
Iterates over the source elements, and each element that is contained in the second
collection and has not yet been yielded is returned.
A comparator can be used to compare the elements.
Example: [1,3,5,7,9].intersect([2,4,6,8,10])
except
Iterates over the source elements, and each element that is contained in the second
collection and has not yet been yielded is returned.
A comparator can be used to compare the elements.
Example: [1,3,5,7,9].except([1,2,3,4,5]) //returns 2,4,7,9
toArray
Iterates over the collection and returns an array containing the elements.
toSet
Iterates over the collection and returns a Set containing the elements.
toList
Iterates over the collection and returns a List containing the elements.
toMap
Iterates over the collection and evaluates the keySelector and elementSelector functions
for each element, producing a key and a value . The resulting key and value pairs are
returned in a Map . If no elementSelector was specified, the value is the element itself.
toLookup
Iterates over the source elements and evaluates the keySelector and elementSelector
functions for each element, producing a key and a value . The values with the same key
are grouped together in a Grouping , and the resulting key and the Grouping pairs are
returned in a Map . If no elementSelector is specified, the value for each element is the
element itself.
Example: employees.toLookup(e->e.last, e->e.positionId)
( continued )
Search WWH ::




Custom Search