Created
August 17, 2017 01:58
-
-
Save ItsCalebJones/57699c945f5dd936cf69e7e1a0ca720e to your computer and use it in GitHub Desktop.
Creating a public static dictionary in Java
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
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