Java 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.of and ArrayList.addUpdate a shopping basket
- Comparator.comparingInt and List.sortSort jobs by priority
- List.add and List.addAllInsert two pickup stops before the depot
- List.copyOfFreeze the guest list used to print badges
- List.remove by index or valueTake a cancelled item off a packing list
- List.removeIfClear empty stock bins from the pick list
- List.replaceAllClean the names on two visitor badges
- List.setCorrect the second stop on a shuttle route
- List.toArraySend the badge roster to an older printer
Lists · positions and ranges
- List.containsCheck for a price in a sale list
- List.get, List.size and List.isEmptyRead the second name on the pickup roster
- List.getFirst, List.getLast and List.reversedRead a receipt history newest first
- List.indexOf and List.lastIndexOfFind both visits to the market
- List.subListSelect two orders for the packing bench
Maps · look up and assign
- Map.getOrDefaultLook up stock for an item
- Map.containsKey and Map.containsValueFind a parcel whose driver is still unassigned
- Map.put and Map.getUpdate the count for a shelf label
- Map.putIfAbsentKeep the first reservation for a seat
- Map.removeRelease a locker only for its recorded owner
- Map.replaceChange a room assignment only if it is still current
Maps · combine and transform
- Map.mergeCount products as they are scanned
- Map.compute and Map.computeIfPresentReduce only the stock that is on the ledger
- Map.computeIfAbsentGroup two parcels on one delivery route
- Map.entrySet, Map.keySet and Map.valuesPrint shelf totals in aisle order
- Map.ofEntries and Map.copyOfKeep the price shown on yesterday's menu
- Map.putAll and Map.clearApply weekend opening hours
- Map.replaceAll and Map.forEachAdd a packing charge to each listed price
Other collection guides
- Collectors.groupingByGroup orders for a daily report
- Optional.map and orElseShow a name when one is available
- Collections.minFind the cheapest item in a basket
- CompletableFuture.allOfWait for two shop totals before producing a report
- IntStream.sumAdd the prices on a shopping list
- Stream.filter and countCount items at the offer price
- Stream.filter and limitFind the first two available seats