tag:blogger.com,1999:blog-694855878384792308.post4723163550484324343..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to use Java Enum in Switch Case Statement - Exampel Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-694855878384792308.post-876130698460997832014-12-18T20:37:22.477-08:002014-12-18T20:37:22.477-08:00if switch is to take only int, how can it accept S...if switch is to take only int, how can it accept String (java 1.7 onwards)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-69186867045768377402013-10-24T20:12:52.690-07:002013-10-24T20:12:52.690-07:00For those, who wants to learn more, Enum in Switch...For those, who wants to learn more, Enum in Switch case is implemented using ordinal() method. Since as per Java programming language, we can only pass int into Switch case, ordinal() returns int. So above code of Enum with Switch will actually translate into <br /><br />switch(today.ordinal()){<br /><br />case Monday.ordinal():<br />break;<br /><br />case Tuesday.ordinal():<br />break;<br />}<br /><br /><br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-4919086072395261722013-08-29T20:07:49.409-07:002013-08-29T20:07:49.409-07:00You can also use Switch case directly with String ...You can also use Switch case directly with String from Java 1.7 onwards, but still using Enum and Switch case is much better of overall code quality as, String are brittle and case sensitive.Javin Paulnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-30318320958055337802012-10-01T20:57:15.482-07:002012-10-01T20:57:15.482-07:00thanks for your sharing about switch case in jaVathanks for your sharing about switch case in jaVaanimateholichttp://mathsanimation.blogspot.com/2012/10/pernyataan-switch-dengan-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-14137955930792438032012-09-30T08:28:50.928-07:002012-09-30T08:28:50.928-07:00Hi,
Great blog! Is there an email address I can c...Hi,<br /><br />Great blog! Is there an email address I can contact you in private?Nikos Maravitsashttps://www.blogger.com/profile/15031926888218632378noreply@blogger.com