Forums Register Login

how to put all the enum element into a list

+Pie Number of slices to send: Send
I have to put all the enum elements into my newly created list.
The enum is created in class enum as shown below

public enum salesStatus {
OPEN, BIDDING, ON_HOLD, CLOSED
}

public class MainClass{
List list = new List();

}

trouble is , how do i put all the OPEN, BIDDING, ON_HOLD, CLOSED
into the list.

Thanks
+Pie Number of slices to send: Send

Every enum has a static values() method, which isn't mentioned in tha API docs. It returns an array of all the constants declared in that enum. If you don't really need a List, you can use the array directly (and you don't have to include the generic type when you declare the List, but you might as well).
+Pie Number of slices to send: Send
Moving this to Java in General (Beginner)...

Henry
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 21662 times.
Similar Threads
how to put all the enum element into a list
Three questions about Java Scripting API.
Nested Enums and Classes
Where To Package Enums
Related to Enum const specific class body
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:56:27.