Groovy lists and maps
Work with ordered lists and key-value lookups. Follow a pickup roster, change a booking, or combine stock counts from two deliveries.
Lists · build and edit
- List as String arraySend the badge roster to an older printer
- List.addAdd the last student to the bus register
- List.addAll at an indexInsert two pickup stops before the depot
- List.collectClean the names on two visitor badges
- List.findAllClear empty stock bins from the pick list
- List.removeAtTake a cancelled item off a packing list
- List.setCorrect the second stop on a shuttle route
Lists · positions and ranges
- List range subscriptSelect two orders for the packing bench
- List.getRead the second name on the pickup roster
- List.reverseRead a receipt history newest first
Maps · look up and assign
- Map subscript assignmentUpdate the count for a shelf label
- Map.containsKeyFind a parcel whose driver is still unassigned
- Map.putIfAbsentKeep the first reservation for a seat
- Map.remove with expected ownerRelease a locker only for its recorded owner
Maps · combine and transform
- Map.computeIfPresentReduce only the stock that is on the ledger
- Map.putAllApply weekend opening hours
- Map.sort and collectPrint shelf totals in aisle order
- Map.withDefaultGroup two parcels on one delivery route
Other collection guides
- countByCount records by an extracted key
- collateSplit a work queue into fixed-size batches
- injectAccumulate an invoice in integer cents
- collectEntriesBuild a lookup map with a duplicate-key rule
- List.containsCheck for a price in a sale list
- Map.getOrDefaultShow a default when a product has no stock entry
- countCount items at the offer price
- minFind the cheapest item in a basket
- sumAdd the prices on a shopping list