Skip to content

Instantly share code, notes, and snippets.

@mzimecki
Last active December 19, 2015 22:39
Show Gist options
  • Save mzimecki/6028702 to your computer and use it in GitHub Desktop.
Save mzimecki/6028702 to your computer and use it in GitHub Desktop.
[Java] EnumSet order
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