Courseiva
Arrays and MethodsmediumMultiple ChoiceObjective-mapped

1Z0-811 Arrays and Methods Practice Question

A company manages employee data stored in an array of Employee objects. The HR application frequently needs to find an employee by ID. The current implementation uses a linear search through the array each time. Performance reports indicate that this search is becoming a bottleneck as the company grows. The array is not sorted, and the company does not want to sort it because the order is meaningful for display. The array is large and frequently updated. The development team considers several options to improve the search performance without changing the array order. Which approach should they implement?

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

Create a HashMap<Integer, Employee> that maps IDs to Employee objects, and maintain it alongside the array.

The best choice because using a HashMap<Integer, Employee> provides O(1) average-time lookups, which is far superior to linear search. The HashMap can be maintained alongside the array without disturbing the array order, as updates to the array are reflected in the HashMap. Option B (parallel streams) still performs a linear search (O(n)) and adds overhead for parallelization, so it does not solve the bottleneck. Option C (HashSet of IDs) only allows checking existence but does not provide the Employee object; you would still need to search the array to retrieve the Employee, so it does not reduce complexity. Option D (binary search on a sorted copy) requires O(n log n) time to sort a copy for each search, which is even worse than linear search.

Answer analysis

Option-by-option breakdown

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

  • Create a HashMap<Integer, Employee> that maps IDs to Employee objects, and maintain it alongside the array.

    Why this is correct

    Provides O(1) lookup and preserves array order.

  • Use parallel streams to perform the search in parallel.

    Why it's wrong here

    Still O(n) and parallel overhead may not improve single lookup.

  • Convert the array to a HashSet of employee IDs and use contains() to check existence.

    Why it's wrong here

    Does not provide direct access to the Employee object; still need to find it.

  • Use Arrays.binarySearch() on the array after temporarily sorting a copy each time.

    Why it's wrong here

    Sorting a copy each search is O(n log n) per lookup, far worse.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.