Iterate enum valuesTag(s): Language


public class EnumTest {
  
  enum Simpsons {
    HOMER ("Homer"), 
    MADGE ("Marge"), 
    MAGGIE  ("Maggie"), 
    BART ("Bart"), 
    LISA ("Lisa");
    
    private String name;
    Simpsons(String name) { this.name = name; }
    public String getName() { return name; }
   }

  public static void main (String ... args) {
    for (Simpsons member : Simpsons.values()) {
      System.out.println(member.getName());
    }
  }
}

/*
  output :

      Homer
      Marge
      Maggie
      Bart
      Lisa

*/

blog comments powered by Disqus