ENUM Switch Case is Standard way to Implement Switch with String?
<p>i want to implement Switch Case based on String,</p><p>java 1.7 is supporting Switch Case with String, but for before version's, it can be possible with Enum. Is this the best and standard way to implement.</p><p><strong>Example</strong></p><pre><br /><code>public enum MethodType {<br /> DOUBLE,LIST,STRING,ARRAYLIST,FLOAT,LONG;<br /> }<br /> public static void main( String[] args ) {<br /> String value = "DOUBLE";<br /> switch( MethodType.valueOf( value ) ) {<br /> case DOUBLE:<br /> System.out.println( "It's a double" );<br /> break;<br /> case LIST:<br /> System.out.println( "It's a list" );<br /> break;<br /> }<br /> }<br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34470195/enum-switch-case-is-standard-way-to-implement-switch-with-string">http://ift.tt/1J98zlK</a></h2>
Nhận xét
Đăng nhận xét