the enum class is the common base class of all java language enumeration types.
examplelet us see an example to iterate over enum values using for loop −
public class demo { public enum vehicle { car, bus, bike } public static void main(string[] args) { for (vehicle v : vehicle.values()) system.out.println(v); }}
输出carbusbike
example现在让我们看另一个例子,使用for each循环迭代枚举值:
import java.util.stream.stream;public class demo { public enum work { table, chair, notepad, pen, laptop } public static void main(string[] args) { stream.of(work.values()).foreach(system.out::println); }}
输出tablechairnotepadpenlaptop
以上就是在java中迭代枚举值的详细内容。