Last active
December 19, 2015 22:39
-
-
Save mzimecki/6028702 to your computer and use it in GitHub Desktop.
[Java] EnumSet order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.EnumSet; | |
/** | |
* EnumSet uses natural order which means the order in which the enum constants are declared. | |
*/ | |
public class EnumSetTest { | |
private enum MyEnum {A, B, C, D} | |
public static void main(String [] args) { | |
EnumSet<MyEnum> enumSet = EnumSet.of(MyEnum.B, MyEnum.D, MyEnum.A, MyEnum.C); | |
//will print A, B, C, D | |
for(MyEnum e : enumSet) { | |
System.out.println(e.name()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment