Home » Java Switch with String

Java Switch with String

by Online Tutorials Library

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 

You may also like