Java中Enum方法toString与ordinal方法

Java中Enum方法toString与ordinal方法

public enum Language {
     C, Java, PHP;
}

public class EnumDemo {

    public static void main(String args[]) {
           
         // returns the name of this enum constant(String)
         System.out.println("Programming in " + Language.C.toString());       
         System.out.println("Programming in " + Language.Java.toString());  
         System.out.println("Programming in " + Language.PHP.toString());  
         // returns the ordinal of this enum constant,start with 0 (int)
         System.out.println("Programming in " + Language.C.ordinal());       
         System.out.println("Programming in " + Language.Java.ordinal());  
         System.out.println("Programming in " + Language.PHP.ordinal());  
       }
}

 

posted @ 2015-09-09 23:19  harry_ma  阅读(2758)  评论(1编辑  收藏  举报
 aa
    部分内容来自网络,如有异议,请联系我.     


      成绩来自坚持, 灵感来自激情。

                                                               感谢父母和亲朋好友的爱与支持!