June 2018
Beginner
722 pages
18h 47m
English
Assuming the enum class looks like the following:
enum Transport { AIRPLANE, BUS, CAR, TRAIN, TRUCK }
Then the code that demonstrates the four methods of EnumSet may look like this:
EnumSet<Transport> set1 = EnumSet.allOf(Transport.class);System.out.println(set1); //prints: [AIRPLANE, BUS, CAR, TRAIN, TRUCK]EnumSet<Transport> set2 = EnumSet.range(Transport.BUS, Transport.TRAIN);System.out.println(set2); //prints: [BUS, CAR, TRAIN]EnumSet<Transport> set3 = EnumSet.of(Transport.BUS, Transport.TRUCK);System.out.println(set3); //prints: [BUS, TRUCK]EnumSet<Transport> set4 = EnumSet.complementOf(set3);System.out.println(set4); //prints: [AIRPLANE, CAR, TRAIN]
Read now
Unlock full access