Kotlin 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.filterNotClear empty stock bins from the pick list
- List.mapClean the names on two visitor badges
- List.toListFreeze the guest list used to print badges
- List.toTypedArraySend the badge roster to an older printer
- MutableList.addAdd the last student to the bus register
- MutableList.addAllInsert two pickup stops before the depot
- MutableList.removeAtTake a cancelled item off a packing list
- MutableList.setCorrect the second stop on a shuttle route
Lists · positions and ranges
- List.asReversedRead a receipt history newest first
- List.getOrNullRead the second name on the pickup roster
- List.indexOf and lastIndexOfFind both visits to the market
- List.sliceSelect two orders for the packing bench
Maps · look up and assign
- Map.containsKeyFind a parcel whose driver is still unassigned
- MutableMap.getOrPutKeep the first reservation for a seat
- MutableMap.remove with expected valueRelease a locker only for its recorded owner
- MutableMap.replace on the JVMChange a room assignment only if it is still current
- MutableMap.set and getUpdate the count for a shelf label
Maps · combine and transform
- Map.entries and toSortedMapPrint shelf totals in aisle order
- Map.mapValuesAdd a packing charge to each listed price
- MutableMap.getOrPut for listsGroup two parcels on one delivery route
- MutableMap.putAllApply weekend opening hours
Other collection guides
- groupingBy and eachCountCount order statuses without storing each group
- sortedWith and compareByRank equal scores by a second key
- windowedDetect an increase in three-reading averages
- associateByIndex records by a possibly repeated identifier
- List.containsCheck for a price in a sale list
- Map.getOrDefaultShow a default when a product has no stock entry
- chunkedPack mailing labels in groups of two
- countCount items at the offer price
- minOrNullFind the cheapest item in a basket
- sumAdd the prices on a shopping list