• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enum to String array

 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch!

I think what you have there is fine. Disclaimer, I'm not a world expert on Java .
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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

Thanks
Suresh
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Suresh Kumar Bethanasamy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic