← Quiz: Spring Boot Caching: all 10 questions
Quiz: Spring Boot Caching · Question 9 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
Map<String, String> cache = new HashMap<>();
Map<String, String> db = new HashMap<>(Map.of("c1", "Java"));
String a = cache.computeIfAbsent("c1", db::get);
db.put("c1", "Core Java");
String b = cache.computeIfAbsent("c1", db::get);
cache.remove("c1");
String c = cache.computeIfAbsent("c1", db::get);
System.out.println(a + " | " + b + " | " + c);
}
}
- A.Java | Core Java | Core Java
- B.Java | Java | Java
- C.Java | Java | Core Java
- D.Core Java | Core Java | Core Java
Answer & explanation
Correct answer: Java | Java | Core Java
b is a stale hit; only after remove (eviction) does c load the new value.
Can you get the rest right without peeking?
Take the timed Quiz: Spring Boot Caching quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →