SWEN221 - Mutant Lambdas

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/16

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:23 AM on 5/24/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

17 Terms

1
New cards

Give an example of lambda use for .forEach.

books.forEach(book -> System.out.println(book.title()));

2
New cards

Give an example of lambda use for Map.forEach.

parkingLot.forEach((slotId, car) ->
  System.out.println("Slot " + slotId + ": " + car.plate()));

3
New cards

Give an example of lambda use for .removeIf.

emails.removeIf(email -> email.endsWith("@spam4.me"));

4
New cards

Give an example of lambda use for Set.removeIf.

users.removeIf(u -> !u.active());

5
New cards

Give an example of lambda use for removing map entries with .removeIf.

nameToAge.entrySet().removeIf(e -> e.getValue() >= 60);

6
New cards

Give an example of lambda use for List.replaceAll.

prices.replaceAll(oldPrice -> oldPrice * 1.10);

7
New cards

Give an example of lambda use for Map.replaceAll.

eventCounts.replaceAll((event, oldCount) -> 0);

8
New cards

Give an example of lambda use for Map.merge.

playerScores.merge(name, newScore, (oldS, newS) -> Math.max(oldS, newS));

9
New cards

Give an example of method-reference use for Map.merge.

playerScores.merge(name, newScore, Math::max);

10
New cards

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);
});

11
New cards

Give an example of lambda use for Map.compute.

inventory.compute(id, (productId, oldAmount) ->
  oldAmount == null ? newAmount : oldAmount + newAmount);

12
New cards

Give an example of lambda use for Map.computeIfAbsent.

cache.computeIfAbsent(fName, name -> _getImage(name));

13
New cards

Give an example of method-reference use for Map.computeIfAbsent.

cache.computeIfAbsent(fName, this::_getImage);

14
New cards

Give an example of lambda use for Map.computeIfPresent.

userProfiles.computeIfPresent(username, (name, oldImage) -> newImage);

15
New cards

Give an example use for mutating only part of a list with List.subList.

Collections.reverse(list.subList(fromIndex, toIndex));

16
New cards

Give an example of using subList with a lambda method.

list.subList(fromIndex, toIndex).removeIf(n -> n < 0);

17
New cards

Give an example use for Map.getOrDefault.

customerPoints.getOrDefault(customerId, 0);