Using EnumSet for Efficient Enum Collections in Java


EnumSet provides a high-performance Set implementation for enum types, much faster than using a regular HashSet.

Source Code

EnumSet weekend = EnumSet.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
for (DayOfWeek day : weekend) {
    System.out.println(day);
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments