Java Strings MCQs with answers Page - 4

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. Which method checks if a string ends with a given suffix?

  • (A) endsWith()
  • (B) hasSuffix()
  • (C) finishWith()
  • (D) ends()

A

Admin • 831.35K Points
Coach

Q. What does `compareTo()` return when strings are equal?

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

A

Admin • 831.35K Points
Coach

Q. Which method changes only the first occurrence of a character?

  • (A) replaceFirst()
  • (B) replace()
  • (C) subString()
  • (D) trim()

A

Admin • 831.35K Points
Coach

Q. What is the result of:
"Hello".equals("HELLO")?

  • (A) true
  • (B) false
  • (C) null
  • (D) Exception

A

Admin • 831.35K Points
Coach

Q. What is the result of:
String s = new String("abc");
String t = "abc";
s == t;

  • (A) true
  • (B) false
  • (C) Compile-time error
  • (D) Runtime error

A

Admin • 831.35K Points
Coach

Q. Which method converts a string to lower case?

  • (A) lowerCase()
  • (B) toLowerCase()
  • (C) convertToLower()
  • (D) smallCase()

A

Admin • 831.35K Points
Coach

Q. Which operator is overloaded for String objects?

  • (A) +
  • (B) -
  • (C) *
  • (D) /

A

Admin • 831.35K Points
Coach

Q. What is returned by:
"Java Programming".contains("Pro")?

  • (A) true
  • (B) false
  • (C) Pro
  • (D) Exception

A

Admin • 831.35K Points
Coach

Q. How can you get the last character of a string `s`?

  • (A) s.charAt(s.length())
  • (B) s.charAt(s.length - 1)
  • (C) s.charAt(s.length() - 1)
  • (D) s.last()

A

Admin • 831.35K Points
Coach

Q. What happens if you try to access an index out of bounds in a string?

  • (A) Returns null
  • (B) Returns 0
  • (C) Throws StringIndexOutOfBoundsException
  • (D) Compiles but skips
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