java枚举类型_Ordinal compareTo

public enum Color {
    RED, BLUE, BLACK, YELLOW, GREEN
}
public class Program {
    //RED, BLUE, BLACK, YELLOW, GREEN
    public static void main(String[] args) {
//        testOrdinal();
        testCompareTo();
    }
    
    public static void testCompareTo(){
        int dis=Color.GREEN.compareTo(Color.RED);
        System.out.println(dis);
    }
    
    public static void testOrdinal(){
        System.out.println(Color.YELLOW.ordinal());
        System.out.println(Color.GREEN.ordinal());
        System.out.println(Color.RED.ordinal());
        System.out.println(Color.BLUE.ordinal());
        System.out.println(Color.BLACK.ordinal());
    }
}

posted on 2012-10-17 17:29  雨渐渐  阅读(457)  评论(0编辑  收藏  举报

导航