June 19, 2016

Switch Case is certainly one of the most widely used programming constructs. It is just as widely used in Java as in any other language.

Up until Java 7, switch in Java did not support String type in the case statement. So, if you want to perform multiple comparisons on Strings, the only way you were able to do it was by using multiple If - Else Statements which is certainly not pretty!

But, then in Java 7 they have introduced Switch With Strings and it was welcomed by everyone who had to write those terrible if-else ladders. So, Let’s see how we can use Strings in a Case statement.