Easy learning with example program codes

Java 7 String in Switch Case Statement

Java switch statement:

Java switch statement is used to execute a block of statement based on the switch expression value. It is like if else if statement.

Java 7 allows us to use string objects in the expression of switch statement.


  • Java switch case String is case sensitive.
  • Java switch case uses String.equals() method to compare the expression value with case values, so it will throw NullPointerException if passed value is null.

Java string in switch case example

package com.codesjava;
public class SwitchStringExampleExample {
	public static void main(String args[]){
		String game = "java";  
        case "sql":  
            System.out.println("Learn sql");  
        case "java":  
            System.out.println("Learn java");  
        case "angularjs":  
            System.out.println("Learn angularjs");  


Learn java


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki