Java String MCQ - Multiple Choice Questions And Answers
Q. What is the length() method used for in Java String?
A. To find the last index of a characterB. To concatenate two strings
C. To convert a string to lowercase
D. To find the number of characters in a string
Q. Which method is used to compare two strings for equality in Java String?
A. compare()B. equals()
C. compareTo()
D. hashCode()
Q. Which method is used to convert a string to uppercase in Java String?
A. toUppercase()B. toUpperCase()
C. upperCase()
D. convertCase()
Q. Which method is used to find the index of a specified character in Java String?
A. indexOf()B. findIndex()
C. searchIndex()
D. locateIndex()
Q. Which method is used to replace characters in a string with another character in Java String?
A. replace()B. replaceChar()
C. replaceAll()
D. replaceCharacter()
Q. Which method is used to extract a substring from a string in Java String?
A. substring()B. extractString()
C. getSubstring()
D. subString()
Q. Which method is used to remove leading and trailing whitespace from a string in Java String?
A. strip()B. trim()
C. removeWhitespace()
D. removeSpaces()
Q. Which method is used to split a string into an array of substrings based on a specified delimiter in Java String?
A. split()B. divide()
C. separate()
D. break()
Q. Which method is used to check if a string starts with a specified prefix in Java String?
A. startsWith()B. hasPrefix()
C. checkPrefix()
D. beginWith()
Q. Which method is used to convert a string to lowercase in Java String?
A. toLower()B. toLowerCase()
C. lowerCase()
D. convertToLower()
Q. Which of the following code snippets correctly initializes a String variable in Java?
A.String name = "John";B.
String name = new String("John");C.
String name; name = "John";D.
String name; name = new String("John");