southman avatar

As of java version 1.7, it is also possible to declare String type in switch statement.

south-man

Published: 13 Apr 2018 › Updated: 13 Apr 2018As of java version 1.7, it is also possible to declare String type in switch statement.

As of java version 1.7, it is also possible to declare String type in switch statement.

I did not know that it was possible to have a String type when declaring a switch statement. Since version 1.7, it was possible, but I realized that it could not be done by changing the character to Enum type and using the switch statement or the if else statement.

Starting with Java 1.7, it becomes available as follows. It's easy. Now I know.

switch (oMyGoodness) {
case "I am me": case "You are you":
result = 0; break;
case "I am you": case "You are me":
result = 1; break;
}

Leave As of java version 1.7, it is also possible to declare String type in switch statement. to:

Written by

Read more #java posts


Best Posts From southman

We have not curated any of south-man's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From southman