Question 16
Back to Exercise
What is the output of the following Java program?
import java.util.EnumSet;
enum Day { MON, TUE, WED, THU, FRI, SAT, SUN }
public class Main {
public static void main(String[] args) {
EnumSet<Day> work = EnumSet.range(Day.MON, Day.FRI);
EnumSet<Day> weekend = EnumSet.complementOf(work);
EnumSet<Day> gym = EnumSet.of(Day.SUN, Day.TUE, Day.THU);
EnumSet<Day> gymOnWorkdays = EnumSet.copyOf(gym);
gymOnWorkdays.retainAll(work);
System.out.println(weekend + " " + gym + " " + gymOnWorkdays + " " + work.size());
}
}
- A [SAT, SUN] [TUE, THU, SUN] [TUE, THU] 5 Correct
- B [SAT, SUN] [SUN, TUE, THU] [TUE, THU] 5
- C [SUN, SAT] [TUE, THU, SUN] [TUE, THU] 5
- D [SAT, SUN] [TUE, THU, SUN] [TUE, THU, SUN] 5
Correct Answer: Option A
EnumSet always keeps declaration order, whatever order the constants were added in.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!