Courseiva
Java Basics and SyntaxhardMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

You are developing a Java application for a library management system. The system must track the number of books in each genre. You need to store genre names (String) and their counts (int). The data will be accessed frequently and modified rarely. Which Java data structure should you use to store this mapping efficiently, while ensuring that genre names are unique?

⚠ Common exam trap

Oracle often tests the distinction between collections that store single elements (like HashSet) versus those that store key-value pairs (like HashMap), leading candidates to choose HashSet when a mapping is required.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

HashMap<String, Integer>

HashMap<String, Integer> is the correct choice because it stores key-value pairs, where each genre name (String) is a unique key mapped to its count (Integer). This provides O(1) average-time complexity for lookups and updates, which is ideal for frequent access and rare modifications. The HashMap ensures key uniqueness via its hash-based implementation, directly meeting the requirement of unique genre names.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ArrayList<Book>

    Why it's wrong here

    Not a mapping structure; duplicates allowed.

  • LinkedList<String>

    Why it's wrong here

    No mapping, inefficient search.

  • HashSet<String>

    Why it's wrong here

    Only keys, no count.

  • HashMap<String, Integer>

    Why this is correct

    Maps unique genre to count.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.