#212 HashMap Behavior When Adding Keys

Companies:
Sberbank
Themes:
JavaCollections & GenericsCode Review

What will be printed to the screen?

public class Main
{
    public static void main(String[] args) {
        HashMap<String, Integer> languages = new HashMap<>();

        languages.put("Java", 8);
        languages.put("JavaScript", 1);
        languages.put("Python", 3);
        languages.put("Java", 21);
        languages.put(null, 666);

        System.out.println(languages.size());
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in