All Flashcards
Why are strings in Java objects?
They belong to the String class, providing built-in methods for manipulation.
What is the difference between using == and .equals() to compare strings?
== compares references, .equals() compares content.
Explain string immutability.
Strings cannot be changed after creation; any modification creates a new String object.
Why are pre-initialized strings more efficient?
Java can reuse them, avoiding the creation of new objects for identical string literals.
What are the differences between creating a String with a literal and using the new keyword?
Literal: potentially reuses existing strings. new: always creates a new object.
What is a String in Java?
An object representing a sequence of characters.
What is a String literal?
A sequence of characters enclosed in double quotes.
What is the String class?
A class in Java used to create and manipulate strings.
Define pre-initialized String.
A string created using double quotes, e.g., String str = "text";
Define String constructor.
Creating a string object using the new keyword, e.g., String str = new String("text");