Im working on java, I have created an enum as follows:
public enum myEnum
{
india,
russian,
england,
north America
}
Above
I'm gong to go ahead and guess why you want a space in the name; because you want to reference it as a string.
So do this:
public enum MyEnum {
INDIA("India"),
RUSSIAN("Russian"),
ENGLAND("England"),
NORTH_AMERICA("North America");
private String name;
MyEnum(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
You can consider overriding string.
public toString() {
return name;
}
An advantage of overriding toString() is that this string can also be used in MyEnum .valueOf(myString). So overriding toString basically creates a HashMap of the enum values.