Pages

Thursday, October 13, 2011

JDK7: String in Switch Example

switch in Java was always considered not particularly useful prior to Java 5. In Java 5, enum was added to the language. This made it more useful to use switch statements, but was still incomplete. A feature request that has been long in waiting is the ability to use a String in a switch.

Finally, in Java 7 SE we get the ability to use a String in a switch statement. This feature, I believe, will make the use of switch more prevalent in code which is post JDK 6.

The example below was developed using NetBeans 7.1 Beta on Oracle Solaris Express 11. The NetBeans Java project is located here: StringSwitch.zip.

This code was presented at the Greenville Java Users Group. The Unicode has a hidden message which is displayed when run.

StringSwitch.java


1 comment:

  1. Good example and String in Switch is more useful.

    ReplyDelete