12 Questions
What is the index of the character 'o' in the string "Hello World"?
7
Which method is used to find the length of a string in Java?
length()
How can a String object be created using a string literal in Java?
String str = "Hello"
Which package provides the String class in Java?
java.lang
What is the difference between comparing strings using '==' and the equals() method?
Using '==' compares the references of the objects, while equals() compares the content of the strings.
What happens when two string literals with the same content are compared using '=='?
They share the same memory location.
Why is the String class considered immutable?
Because its contents cannot be changed once it is created.
What does the statement 'new String("Computer")' do in Java?
It creates a new string object with the content 'Computer' in a different memory location.
What does the method 'trim()' do when used on a string?
Returns a new string with leading and trailing whitespace removed
What does the method 'substring(1, 3)' return when used on the string 'Java'?
Returns a new string 'av'
What is the result of the method 'toUpperCase()' when used on the string 'Java'?
Returns a new string 'JAVA'
What does the method 'replace('a', 'o')' do when used on the string 'Java'?
Returns a new string with specified old character replaced by new character
Learn about the String class in Java and its methods for creating and manipulating strings, including details about indexing, length, and character sequences. This quiz will test your understanding of basic string operations in Java.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free