Checking if a String is contained in an Enum Set in O(1)
Clash Royale CLAN TAG #URR8PPP Checking if a String is contained in an Enum Set in O(1) Let's say I have an enum like the following: public enum Utils { UTIL_1, UTIL_2, ... UTIL_n } Now, I have Set<Utils> myUtils , which contains a bunch of these enum entries. Some other module (on which I don't have any control) gives me one such util name (say " UTIL_i ") as a String. I need to check if it is contained in the set myUtils . Is there any way to perform this operation in O(1)? I understand, I could change the set to be a set of Strings, and then do a .contains() on that, but I want to keep it as a last resort. Set<Utils> myUtils UTIL_i myUtils Update : Following the suggestions in the answer, I tried a little experiment. I created a small code snippet to generate a java file which is an enum of a fixed size. I tried with size 1000, 2500, 5000. An enum of size 10000 showed me the error The code for the static initializer is exceeding the 65535 bytes lim...