Courseiva
Question 269 of 481
Arrays and MethodsmediumMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

In a login system, the authentication method receives an array of user roles as a String[] and checks if a specific role is present. The array may be large (thousands of roles), and the method is called frequently for each user request. Performance is critical. The array is static and does not change after initialization. Which approach is most efficient for repeated checks?

⚠ Common exam trap

Oracle often tests the misconception that sorting and binary search is the most efficient approach for repeated lookups, but they overlook the upfront sorting cost and the fact that HashSet provides O(1) average-time complexity, which is superior for static, frequently queried data.

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

Convert the array to a HashSet once and reuse it for lookups.

Converting the array to a HashSet once provides O(1) average-time complexity for subsequent contains() checks, which is far more efficient than O(n) linear search or O(log n) binary search when the method is called frequently on a static array. The HashSet leverages hash codes for direct bucket lookup, making it ideal for repeated membership tests on large, unchanging data sets.

Answer analysis

Option-by-option breakdown

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

  • Use a for loop to iterate and compare each string.

    Why it's wrong here

    O(n) per check, slower for frequent checks.

  • Sort the array and use Arrays.binarySearch().

    Why it's wrong here

    Sorting is O(n log n) once, but binary search is O(log n). Still, HashSet is faster for large n.

  • Convert the array to a HashSet once and reuse it for lookups.

    Why this is correct

    HashSet provides O(1) average lookup time.

  • Use a List and the contains() method.

    Why it's wrong here

    List.contains() is O(n) for ArrayList.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.