Skills101
← All practice quizzes

Quiz: HashMap and Maps

5 questionsNo time limitPass: 60%+10 XP on first pass

Use HashMap, LinkedHashMap and TreeMap, count frequencies, learn how HashMap works inside (buckets, hashing), the equals/hashCode contract, and Comparable vs Comparator.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    import java.util.*;
    public class Main {
        public static void main(String[] args) {
            Map<String, Integer> m = new HashMap<>();
            m.put("x", 1);
            m.put("x", 2);
            System.out.println(m.size() + " " + m.get("x"));
        }
    }
    
  2. Question 2

    What is HashMap's default load factor?

  3. Question 3

    If you override equals() in a key class, what else must you override?

  4. Question 4

    Which Map keeps its keys sorted?

  5. Question 5

    Which interface lets you define MANY different sort orders outside the class?