Java Strings MCQs with answers Page - 2

You will find multiple-choice questions (MCQs) related to #Java Strings here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 831.35K Points
Coach

Q. What will this return?
"Java".indexOf('a');

  • (A) 0
  • (B) 1
  • (C) 2
  • (D) -1

A

Admin • 831.35K Points
Coach

Q. Which method checks if a string starts with a given prefix?

  • (A) starts()
  • (B) startsWith()
  • (C) beginWith()
  • (D) hasPrefix()

A

Admin • 831.35K Points
Coach

Q. What does trim() do?

  • (A) Removes all spaces in the string
  • (B) Removes leading and trailing whitespace
  • (C) Removes characters from the end
  • (D) Removes newline characters only

A

Admin • 831.35K Points
Coach

Q. Which method splits a string into an array?

  • (A) break()
  • (B) tokenize()
  • (C) split()
  • (D) explode()

A

Admin • 831.35K Points
Coach

Q. What is the output?
String s = "abc";
s = s + "d";
System.out.println(s);

  • (A) abcd
  • (B) abc
  • (C) cd
  • (D) abc+d

A

Admin • 831.35K Points
Coach

Q. Which method is used to check if a string contains another string?

  • (A) has()
  • (B) includes()
  • (C) contains()
  • (D) match()

A

Admin • 831.35K Points
Coach

Q. How can you convert a string to a character array?

  • (A) toCharArray()
  • (B) split('')
  • (C) charArray()
  • (D) parseChars()

A

Admin • 831.35K Points
Coach

Q. Which method is used to compare two strings ignoring case?

  • (A) equals()
  • (B) compareTo()
  • (C) equalsIgnoreCase()
  • (D) matchIgnoreCase()

A

Admin • 831.35K Points
Coach

Q. What is the result of
"Hello".substring(1, 4)?

  • (A) Hel
  • (B) ell
  • (C) llo
  • (D) ellO

A

Admin • 831.35K Points
Coach

Q. Which method returns the Unicode value of the character at a given index?

  • (A) charCodeAt()
  • (B) codePointAt()
  • (C) getCode()
  • (D) unicodeAt()
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More