Java Strings MCQs with answers Page - 3

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 is the result of:
String s = null;
s += "Java";
System.out.println(s);

  • (A) Java
  • (B) nullJava
  • (C) null
  • (D) Runtime error

A

Admin • 831.35K Points
Coach

Q. Which method replaces characters in a string?

  • (A) change()
  • (B) replace()
  • (C) substitute()
  • (D) alter()

A

Admin • 831.35K Points
Coach

Q. What does this return?
"abcde".substring(2);

  • (A) ab
  • (B) abc
  • (C) cde
  • (D) de

A

Admin • 831.35K Points
Coach

Q. How can you check if a string is empty?

  • (A) s.length() == 0
  • (B) s.isEmpty()
  • (C) s == ""
  • (D) All of the above

A

Admin • 831.35K Points
Coach

Q. Which is true about the `==` operator for strings?

  • (A) It compares values
  • (B) It compares references
  • (C) It always returns true
  • (D) It throws exception if null

A

Admin • 831.35K Points
Coach

Q. What does this print?
System.out.println("hello".toUpperCase());

  • (A) HELLO
  • (B) hello
  • (C) Hello
  • (D) Compile-time error

A

Admin • 831.35K Points
Coach

Q. Which method returns the hash code of a string?

  • (A) hash()
  • (B) hashcode()
  • (C) getHash()
  • (D) hashCode()

A

Admin • 831.35K Points
Coach

Q. What does equalsIgnoreCase() return?

  • (A) true or false
  • (B) 0 or 1
  • (C) true only
  • (D) an integer

A

Admin • 831.35K Points
Coach

Q. Which of these is an immutable class?

  • (A) StringBuilder
  • (B) StringBuffer
  • (C) String
  • (D) None

A

Admin • 831.35K Points
Coach

Q. What is printed?
System.out.println("abc" + 1 + 2);

  • (A) abc12
  • (B) abc3
  • (C) 3abc
  • (D) Compilation error
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