How to Loop Through an Enum in Java


In this example we will show the method to loop through an enum in Java.

Source Code

package com.beginner.examples;

enum Score {
  A,
  B,
  C
}

public class LoopEnum { 
  public static void main(String[] args) {
    for (Score s : Score.values()) { // loop through an enum
      System.out.println(s);
    }
  } 
}

Output:

A
B
C
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments