Convert Enum to String
Hello!Somebody knows how can I convert an Enum variable to an String variable?Thanks in advance!Roger.
Now, if you mean the Enumeration object, that can be converted to a string, just check the api docs for a "sort of" example.
String name;
StringBuffer buffer;
While(enumer.hasElements())
{
name=enumer.nextElement();
///do with the string what you want or
buffer.append(enumer.nextElement().Tostring());
}
buffer.toString()
that 's will work plz note that in jdk1.5 enum is a keyword
Hello again RizwanZahid!Your sugestion worked perfectly, but I've one more rookie question :-) do you know how can I make the inverse proccess... I mean, convert the string variable into an enumeration again?Thank you very much,Roger.
Sure: split the strings on some split character, and then put the individual stings in a Vector. A decent spilt function should be out here somewhere, just use the search.