Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to put all the enum element into a list

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to Java in General (Beginner)...

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!