Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java Switch String

The Switch statement is a beautiful alternative to multiple if else, when all we want to do is match a variable's value to one of many values, to determine what to do. The switch statement is both concise, readable, and have better performance compared to multiple if else version. One issue though, before Java 7 was introduced, we can't use String value with switch statements. That is not fun as String is a well used data type. Sometimes we don't want to define enum and just want to work with Strings. Below are some way on how to use String in Java Switch statements.



This post first appeared on JavaDevNotes, please read the originial post: here

Share the post

Java Switch String

×

Subscribe to Javadevnotes

Get updates delivered right to your inbox!

Thank you for your subscription

×