WeakHashMap size

Report a typo

Now let's see if you understand how WeakHashMap operates. Write the map size on line 10 of the code below.

public class WeakHashMapDemo {
    public static void main(String[] args) throws InterruptedException {
        Map<Person, String> map = new WeakHashMap<>();
        map.put(new Person("Joshua Bloch", 1961), "Effective Java");
        map.put(new Person("Bruce Eckel", 1957), "Thinking in Java");
        
        System.gc();
        Thread.sleep(250);

        System.out.println(map.size());
    }
}
Enter a number
___

Create a free account to access the full topic