You need to count votes by candidate name. Which collection pattern is most direct?

Practice this question from Quiz: Collection Comparisons, with options and an explanation.

Question

You need to count votes by candidate name. Which collection pattern is most direct?

Option A — Correct answer

HashMap<String, Integer> frequency map

A map is ideal for key-to-count storage.

Option B

ArrayDeque as a stack only

Option C

ThreadLocal only

Option D

A single char variable

Explanation

A HashMap from candidate name to count is the standard frequency counting pattern.

Quiz: Collection Comparisons

All questions · Previous question · Next question

Open on QuizMaker