Recall & Review
beginner
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.touch_appClick to reveal answer
intermediate
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.
touch_appClick to reveal answer
beginner
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.
touch_appClick to reveal answer
intermediate
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.
touch_appClick to reveal answer
intermediate
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.
touch_appClick to reveal answer
Which of these creates a String literal in Java?
What happens when you create a String with
new String("abc")?Are Java Strings mutable (can they be changed after creation)?
What is the purpose of the String pool in Java?
Which is more memory efficient for creating Strings?
Explain how Java creates and stores Strings using literals and the new keyword.
Why are Java Strings immutable and what does that mean for modifying text?
