Using String in a Switch Statement – JDK 7

JDK 7 had a lot of list of enhancements. One of it was use of string in a switch statement. In this post we will see how to use String in a switch statement.

We will first see how we needed to code prior to JDK7, when String was not used in the Switch Statement.

Use of If Else instead of Switch prior JDK 7

Now we will see using JDK 7 how we can simplify the above code using Switch Case

Use of String in a Switch Statement

Using a String in a Switch Statement is obviously not a very great enhancement as compared to the other enhancements that are been added in JDK 7.
One of my favorites is Try-with-resources Statement
Please do let me know if the post was helpful.

You can also see the list of JDK 7 enhancements Here