with Certified Solutions
What is a string in Java?
✔✔ A sequence of characters enclosed in double quotes.
How do you declare a string in Java?
✔✔ By using the `String` class, such as `String text = "Hello";`.
Are strings mutable in Java?
✔✔ No, strings in Java are immutable, meaning their values cannot be changed after creation.
How do you compare two strings for equality?
✔✔ By using the `.equals()` method, such as `str1.equals(str2)`.
What is the difference between `==` and `.equals()` when comparing strings?
✔✔ `==` checks if two string references point to the same object, while `.equals()` checks if their
values are the same.
1
, How do you find the length of a string?
✔✔ By using the `.length()` method, such as `str.length()`.
What happens if you try to modify a string in Java?
✔✔ A new string object is created, as strings are immutable.
How do you concatenate two strings?
✔✔ By using the `+` operator or the `.concat()` method.
What method converts a string to uppercase?
✔✔ The `.toUpperCase()` method.
How do you extract a portion of a string?
✔✔ By using the `.substring()` method.
What does the `.charAt()` method do?
✔✔ It returns the character at a specific index in the string.
2