Recall & Review
beginner Click to reveal answer
What is the simplest way to create a String in Java?
You can create a String by enclosing text in double quotes, like
String s = "Hello";. This is called a string literal.intermediate Click to reveal answer
What does
new String("text") do compared to a string literal?It creates a new String object in memory, even if the same text exists as a literal. This is less efficient than using literals directly.
beginner Click to reveal answer
Can Strings in Java be changed after creation?
No, Strings are immutable. Once created, their content cannot be changed. Any modification creates a new String object.
intermediate Click to reveal answer
How does Java optimize String creation with literals?
Java uses a String pool to store literals. If a literal already exists, Java reuses it instead of creating a new object.
intermediate Click to reveal answer
What is the difference between
String s = "abc"; and String s = new String("abc");?The first uses the String pool and reuses the literal if available. The second always creates a new String object in memory.
Which of these creates a String literal in Java?
✗ Incorrect
String literals are created by enclosing text in double quotes directly, like
String s = "Hello";.What happens when you create a String with
new String("abc")?✗ Incorrect
Using
new String() always creates a new String object, even if the same text exists in the pool.Are Java Strings mutable (can they be changed after creation)?
✗ Incorrect
Java Strings are immutable, meaning their content cannot be changed after creation.
What is the purpose of the String pool in Java?
✗ Incorrect
The String pool stores unique String literals so Java can reuse them and save memory.
Which is more memory efficient for creating Strings?
✗ Incorrect
String literals are stored in the pool and reused, making them more memory efficient than creating new String objects.
Explain how Java creates and stores Strings using literals and the new keyword.
Think about how Java reuses text in memory.
You got /4 concepts.
Why are Java Strings immutable and what does that mean for modifying text?
Consider what happens if you try to change a String's characters.
You got /4 concepts.
