StringBuilder and Stringbuffer Flashcards
(140 cards)
In Java, the _________ is used to
represent a group of characters.
String class
It is one of the most frequently
used classes in Java programming.
String
When a new string is created,
memory is ________ for it.
allocated
String Literals
Created using __________
Stored in the ____
double quotes
String Pool
If the same value already exists in the pool, Java
_______ it instead of creating a new one.
reuses
_________: Memory is allocated and
freed as the program runs.
Dynamic
________________________
Created using the new keyword or
__________.
Stored in the Heap (general memory area for
objects).
Each new keyword creates a new instance, even
if the value is the same.
Dynamically Constructed Strings
concatenation
The _______ is like a large warehouse
where Java stores data(e.g., Strings,
Cars, Dogs).
Heap
The Heap is like a ________
where Java stores data(e.g., Strings,
Cars, Dogs).
large warehouse
_________: Java
automatically ____________ to
free up memory.
Garbage Collection
removes unused data
_________ (String Constant Pool)
A special area within the _______ for __________
String Pool
Heap
storing strings
_________by reusing identical
strings.
Saves memory
__________ by avoiding
duplicate data.
Improves performance
__________ by avoiding
duplicate data.
Improves performance
Saves memory by reusing ______________.
identical
strings
Improves performance by avoiding
__________.
duplicate data
String Pool (String Constant Pool)
How It Works:
When a string literal is created (e.g.,
“Hello “), Java checks ___________ in the pool.
If it exists, Java returns a _________ to
the existing string.
If it doesn’t exist, Java creates a ____________ and returns its
reference.
if it already exists
reference
new
string in the pool
____________: General memory for ____, _________, and managed by _______.
Heap
data
dynamic
garbage collection
___________: Special memory for strings, optimized for
reuse and efficiency.
String Pool
Use _______ (“text”) for memory efficiency and
new for unique instances.
string literals
Use string literals (“text”) for ___________ and
new for _____________.
memory efficiency
unique instances
String Pool: __________ for strings, optimized for
________ and ________.
Special memory
reuse
efficiency
Strings in Java are ____________, meaning their
values cannot be changed after creation.
immutable
Any operation that seems to modify a string (e.g.,
concatenation, replacement) actually creates a
_________.
new string