Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copy from one enumeration into another!!

 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,
Can i copy the contents of one enumeration into another enumeration.Please help me out.
Thanks in Advance.
Ravi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Enumeration is an (old) interface. Nothing in that interfacce allows you to store new elements in that enumeration. You could of course catenate two (or more) enumerations as follows:

kind regards
 
Ravi Kumar Ravuru
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jos Horsmeier,
Thanks for ur reply.But i need to copy the elements of one enumeration to another enumeration. Is it possible.
Ravi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not possible, like I wrote in my previous reply: an enumeration is simply an interface, nobody knows whether or not the implementing class is able to 'store' additional objects in it. All you can do is iterate over the two enumerations and store the retrieved objects in, say, an ArrayList or Vector or similar.
For the sake of the argument, assume that the 'other' enumeration, where you want to store additional values, is implemented as:

This silly class makes up a perfectly valid Enumeration, but you sure cannot store any elements in it ...
kind regards
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you can do is to copy each element of the original enumeration to a Vector, and then get an enumeration of the vectored elements via the elements() method.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic