Last active
December 27, 2024 13:49
-
-
Save antoni/ae0121449d1da23c2bc0 to your computer and use it in GitHub Desktop.
Random enum value in Java
This file contains hidden or 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
| public enum AcademicDegree { | |
| DEGREE_MSC, DEGREE_PHD, DEGREE_PHD_HAB, DEGREE_PROF; | |
| private static final AcademicDegree[] VALUES = values(); | |
| private static final int SIZE = VALUES.length; | |
| private static final Random RANDOM = new Random(); | |
| public static AcademicDegree getRandomLetter() { | |
| return VALUES[RANDOM.nextInt(SIZE)]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks