Пример

Enum может быть и таким

public enum DaysOfTheWeek {
 MONDAY(1, "first Day"),
 TUESDAY(2, "second day"),
 WEDNESDAY(3, "-"),
 THURSDAY(4, "-"),
 FRIDAY(5, "-"),
 SATURDAY(6, "day of rest"),
 SUNDAY(7, "day of rest");

public int getId() {
 return id;
 }

public String getDescription() {
 return description;
 }
 private int id;
 private String description;
 DaysOfTheWeek (int id, String description){
 this.id = id;
 this.description = description;
 }
 }

Вывести все данные из Enum в удобном виде

 for(DaysOfTheWeek day : DaysOfTheWeek.values()) {
 System.out.printf("%-2d | %-10s | %-10s \n", day.getId(), day, day.getDescription());
 }

Вывод на консоль:

1 | MONDAY     | first Day
2 | TUESDAY    | second day
3 | WEDNESDAY  | —
4 | THURSDAY   | —
5 | FRIDAY     | —
6 | SATURDAY   | day of rest
7 | SUNDAY     | day of rest

Реклама