LearnFrenzy
Sign in Take a free test

Strings and StringBuilder · Java Strings MCQ · Question 19

Using a String in a switch Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

Can a switch statement use a String selector?

  • A No
  • B Yes, since Java 7 – cases are compared with equals() Correct
  • C Only in switch expressions
  • D Only for single characters
Correct Answer: Option B

The comparison is case-sensitive and a null selector throws NullPointerException.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links