develog

enum 본문

Dev/Java

enum

냐옴 2013. 6. 26. 17:46

 

public enum WeekDay {

    SUNDAY(0, "일"),
    MONDAY(1, "월"),
    TUESDAY(2, "화"),
    WEDNESDAY(3, "수"),
    THURSDAY(4, "목"),
    FRIDAY(5, "금"),
    SATURDAY(6, "토");

    private int code;
    private String dayNm;

    private WeekDay(int code, String dayNm) {
        this.code = code;
        this.dayNm = dayNm;
    }

    public int getCode() {
        return code;
    }

    public String getDayNm() {
        return dayNm;
    }
}

 

public class TestEnum {

    public static void main(String[] args) throws Exception {

        System.out.println("START");
        System.out.println("--------------------------------------------");

        for (WeekDay weekDay : WeekDay.values()) {
            System.out.println(weekDay + ", " + weekDay.getCode() + ", " + weekDay.getDayNm());
        }

        WeekDay weekDay = WeekDay.TUESDAY;
        System.out.println(weekDay + ", " + weekDay.getCode() + ", " + weekDay.getDayNm());

        System.out.println("--------------------------------------------");
        System.out.println("END");
    }
}

'Dev > Java' 카테고리의 다른 글

log4sql  (0) 2013.06.28
spring pointcut expression syntax  (0) 2013.06.27
properties  (0) 2013.06.26
String.valueOf(), String.toString()  (0) 2013.06.25
현재 클래스 경로 구하기  (0) 2013.06.19
Comments