How do I loop through an enum in Java? -


this question has answer here:

let's have enum so:

public enum numbers {     one("uno "),     two("dos "),     three("tres "); }  private final string spanishname;  numbers(string spanishname) {     this.spanishname = spanishname; }  public string getspanishname() {     return spanishname; } 

now have method outputs given variable.

public void output(string value) {     printstream.print(value); } 

i want use for loop output values in enum. along lines of this:

for(/*each element in enum*/) {     //output corresponding spanish name } 

ultimate want final output uno dos tres. how can using enums , loop?

for (numbers n : numbers.values()) {    system.out.print(n.getspanishname() + " "); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -