Java Strings MCQs with answers Page - 6

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 • 833.24K Points
Coach

Q. What is the default value of a String reference in Java?

  • (A) Empty string
  • (B) null
  • (C) 0
  • (D) "null"

A

Admin • 833.24K Points
Coach

Q. Which is true about StringBuilder and String?

  • (A) Both are mutable
  • (B) Both are immutable
  • (C) String is immutable, StringBuilder is mutable
  • (D) StringBuilder is immutable

A

Admin • 833.24K Points
Coach

Q. What will this code output?
String str = "";
System.out.println(str.isEmpty());

  • (A) true
  • (B) false
  • (C) Compile error
  • (D) null

A

Admin • 833.24K Points
Coach

Q. How to convert a string to an array of bytes?

  • (A) getBytes()
  • (B) toCharArray()
  • (C) toBytes()
  • (D) charArray()

A

Admin • 833.24K Points
Coach

Q. What is the use of intern() method?

  • (A) To make string mutable
  • (B) To remove whitespace
  • (C) To store the string in the string pool
  • (D) To convert to uppercase

A

Admin • 833.24K Points
Coach

Q. What will "hello".compareTo("hello") return?

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

A

Admin • 833.24K Points
Coach

Q. What is the return type of `charAt()` method?

  • (A) String
  • (B) char
  • (C) Character
  • (D) int

A

Admin • 833.24K Points
Coach

Q. What will happen if you call length() on a null String?

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

A

Admin • 833.24K Points
Coach

Q. What is the difference between "abc" and new String("abc")?

  • (A) No difference
  • (B) Different values
  • (C) One is string literal, the other is new object
  • (D) One is mutable

A

Admin • 833.24K Points
Coach

Q. How many objects are created?
String s1 = "abc";
String s2 = new String("abc");

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 0
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