If I need to add an enum attribute to a list, how do I declare the list? Let us say the enum class is:
public enum Country{ USA, CANADA; }
I want to do:
List<String> l = new ArrayList<>();
l.add(Country.USA);
What needs to be used instead of List<String>?
Should be:
List<Country> l = new ArrayList<Country>();
l.add(Country.USA); // That one's for you Code Monkey :)
If you want the string type use this:
l.add(Country.USA.name());
otherwise the answer of MByD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With