This is one of the most powerful feature of Java SE 7.   The use of Switch-Case statement with string is very common and will help java developers to use this powerful feature in their applications.

I am providing a very basic example below which demonstrates the use of switch-case using string.

 

 

/**

This is a demo of the switch-case statement with strings.
This was introduced in JAVA SE 7.
Author: www.JavaGenious.com

**/
public class SwitchCaseDemo {

    public static void main(String[] args) {

      String month = "January";
		switch (month) {
			case "January" :
			out.println("This is January");
			break;
			case "December" :
			out.println("This is December");
			break;
			case "May" :
			out.println("This is May");
			break;
			case "June" :
			out.println("This is June");
			break;
           }
  }
  
}

Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)