🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.Java | Core Java | Core Java
  2. B.Java | Java | Java
  3. C.Java | Java | Core Java
  4. 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 →