I have two strings which are mentioned below -
HelloWorld
GoodBye
How do I randomly select any one of the strings?
Below is an enum which contains the above two strings and I am supposed to use below enums to randomly select any one of the string between HelloWorld
and GoodBye
public enum StringEnum {
HelloDavid, HelloWorld, GoodBye;
private static final Map<Integer, StringEnum> BY_CODE_MAP = new LinkedHashMap<Integer, StringEnum>();
static {
for (StringEnum rae : StringEnum.values()) {
BY_CODE_MAP.put(rae.ordinal(), rae);
}
}
public static String forCode(int code) {
return BY_CODE_MAP.get(code).name();
}
}
Any idea how this can be done efficiently by getting the strings from enum?