Created
December 29, 2012 20:37
-
-
Save vaskoz/4409209 to your computer and use it in GitHub Desktop.
Compare JDK7 String switch to If-Then-Else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Switch { | |
public String switchTest(String input) { | |
String result = null; | |
switch(input) { | |
case "foo": result = "foo1"; break; | |
case "bar": result = "bar1"; break; | |
case "foo:bar": result = "foo1:bar1"; break; | |
default: result = "no match"; break; | |
} | |
return result; | |
} | |
public String ifThenElseTest(String input) { | |
String result = null; | |
if ("foo".equals(input)) result = "foo1"; | |
else if ("bar".equals(input)) result = "bar1"; | |
else if ("foo1:bar1".equals(input)) result = "foo1:bar1"; | |
else result = "no match"; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment