Skip to content

Instantly share code, notes, and snippets.

@ItsCalebJones
Created August 17, 2017 01:58
Show Gist options
  • Save ItsCalebJones/57699c945f5dd936cf69e7e1a0ca720e to your computer and use it in GitHub Desktop.
Save ItsCalebJones/57699c945f5dd936cf69e7e1a0ca720e to your computer and use it in GitHub Desktop.
Creating a public static dictionary in Java
public enum PUBGSeason {
PRE1_2017("2017-pre1", "Early Access Season #1"),
PRE2_2017("2017-pre2", "Early Access Season #2"),
PRE3_2017("2017-pre3", "Early Access Season #3");
PUBGSeason(String seasonName, String seasonKey) {
this.seasonName = seasonName;
this.seasonKey = seasonKey;
}
private String seasonName;
private String seasonKey;
private static final Map<String, String> map;
public String getSeasonName() {
return seasonName;
}
public String getSeasonKey() {
return seasonKey;
}
static {
map = new HashMap<>();
for (PUBGSeason season : PUBGSeason.values()) {
map.put(season.getSeasonName(), season.getSeasonKey());
}
}
public static String findByKey(String toFind) {
return map.get(toFind);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment