Javatpoint Logo
Javatpoint Logo

String in Switch Statement

In Java 7, Java allows you to use string objects in the expression of switch statement. In order to use string, you need to consider the following points:

  • It must be only string object.
  • String object is case sensitive.
  • No Null object

be careful while passing string object, passing a null object cause to NullPointerException.


String in Switch Statement Example 1

Output:

Let's play Cricket

String in Switch Statement Example 2

Output:

This is a indoor game





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA