1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Give an example of lambda use for .forEach.
books.forEach(book -> System.out.println(book.title()));Give an example of lambda use for Map.forEach.
parkingLot.forEach((slotId, car) ->
System.out.println("Slot " + slotId + ": " + car.plate()));Give an example of lambda use for .removeIf.
emails.removeIf(email -> email.endsWith("@spam4.me"));Give an example of lambda use for Set.removeIf.
users.removeIf(u -> !u.active());Give an example of lambda use for removing map entries with .removeIf.
nameToAge.entrySet().removeIf(e -> e.getValue() >= 60);Give an example of lambda use for List.replaceAll.
prices.replaceAll(oldPrice -> oldPrice * 1.10);Give an example of lambda use for Map.replaceAll.
eventCounts.replaceAll((event, oldCount) -> 0);Give an example of lambda use for Map.merge.
playerScores.merge(name, newScore, (oldS, newS) -> Math.max(oldS, newS));Give an example of method-reference use for Map.merge.
playerScores.merge(name, newScore, Math::max);Give an example of Map.merge where returning null removes the entry.
playerScores.merge(name, newScore, (oldS, newS) -> {
if (newS < 0) { return null; }
return Math.max(oldS, newS);
});Give an example of lambda use for Map.compute.
inventory.compute(id, (productId, oldAmount) ->
oldAmount == null ? newAmount : oldAmount + newAmount);Give an example of lambda use for Map.computeIfAbsent.
cache.computeIfAbsent(fName, name -> _getImage(name));Give an example of method-reference use for Map.computeIfAbsent.
cache.computeIfAbsent(fName, this::_getImage);Give an example of lambda use for Map.computeIfPresent.
userProfiles.computeIfPresent(username, (name, oldImage) -> newImage);Give an example use for mutating only part of a list with List.subList.
Collections.reverse(list.subList(fromIndex, toIndex));Give an example of using subList with a lambda method.
list.subList(fromIndex, toIndex).removeIf(n -> n < 0);Give an example use for Map.getOrDefault.
customerPoints.getOrDefault(customerId, 0);