Courseiva
Primitives, Strings and OperatorshardMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

A financial trading application processes a batch of 10 million trade transactions every night. Each transaction is a String containing trade details such as ID, symbol, quantity, and price. The current implementation uses string concatenation with the += operator in a loop to build a summary report string. The application frequently runs out of memory and takes hours to complete. The server has 16 GB of RAM and runs Java 11. The code cannot be restructured significantly due to regulatory requirements, but performance improvements are allowed. Which course of action will most effectively resolve the performance and memory issues?

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

Replace the String concatenation with StringBuilder.

The performance and memory issues are caused by using String concatenation (+=) inside a loop, which creates many intermediate String objects because Strings are immutable in Java. StringBuilder is mutable and designed for efficient string concatenation without creating intermediate objects, making it the optimal solution. Option A (StringBuilder) is correct. Option B (calling intern()) would not improve performance and could degrade it. Option C (increasing heap size) only postpones the OutOfMemoryError and does not fix the inefficiency. Option D (StringBuffer) is thread-safe but slower due to synchronization; it is unnecessary in this single-threaded context. Therefore, replacing concatenation with StringBuilder is the most effective resolution.

Answer analysis

Option-by-option breakdown

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

  • Replace the String concatenation with StringBuilder.

    Why this is correct

    StringBuilder is mutable and appends to the same buffer, drastically reducing object creation and improving performance. It is the standard solution for repeated string concatenation.

  • Call intern() on the concatenated result at each iteration.

    Why it's wrong here

    intern() manages a pool of strings but does not reduce intermediate object creation during concatenation and can degrade performance due to pool management overhead.

  • Increase the JVM heap size to 32 GB to accommodate the temporary string objects.

    Why it's wrong here

    Increasing heap may postpone out-of-memory errors but does not reduce the number of intermediate objects or improve performance. It is not a true fix.

  • Replace the String concatenation with StringBuffer.

    Why it's wrong here

    Replacing `String` concatenation with `StringBuffer` would improve memory usage and performance over the original approach by using a mutable character sequence. However, `StringBuffer`'s synchronised methods introduce unnecessary overhead in this single-threaded scenario of building one report string. Its thread-safe nature is not required here, making `StringBuilder` the more performant choice for a single-threaded operation. `StringBuffer` would be appropriate if multiple threads were concurrently appending to the same string object, requiring intrinsic synchronisation.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

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.