It's not a secret anymore!*
The moose likes Java in General and the fly likes Enum to String array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Enum to String array" Watch "Enum to String array" New topic
Author

Enum to String array

Jonathan tse
Greenhorn

Joined: May 24, 2009
Posts: 1
Hi everyone,

Due to some API constraint, i need to convert enum.values to a String array and couldn't find any handy library to do this task. Therefore, I write the following code but I just wonder if there is any better way to do this?

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there and welcome to Javaranch!

I think what you have there is fine. Disclaimer, I'm not a world expert on Java .

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Suresh Kumar Bethanasamy
Greenhorn

Joined: Jul 24, 2013
Posts: 2
Hi All,

Can you please provide the examples for copying the enum values into an char array in java.

Thanks
Suresh
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Welcome to the Ranch, Suresh.

Can you explain in more detail what exactly you want - how exactly do you want to store enum values in a char array? What output would you expect?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Suresh Kumar Bethanasamy
Greenhorn

Joined: Jul 24, 2013
Posts: 2
Jesper de Jong wrote:Welcome to the Ranch, Suresh.

Can you explain in more detail what exactly you want - how exactly do you want to store enum values in a char array? What output would you expect?


Dear Jesper,

Thanks for your mail.

My requirement is as follows

Copy the Enum Values into an array and display the values in the array.

Thanks
Suresh
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2250
    
  47
My requirement is as follows

Copy the Enum Values into an array and display the values in the array.

The code has already been given for copying the enum values names into a string array. Your requirement is very similar although you state you want to use char array (why?) so you will need an array of arrays. You can use the code above as the basis of what you want to do.
If there is something which you don't understand then please say and we will explain it to you but we won't just write the code for you.
 
jQuery in Action, 2nd edition
 
subject: Enum to String array