Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through enum in java [duplicate]

Tags:

java

enums

I have a enum for various operations, I want to iterate through the enum Operations

public enum Operations  { create,update,delete,view,compare,login } 

How can i achieve this?

like image 402
AabinGunz Avatar asked May 30 '11 09:05

AabinGunz


People also ask

Can we loop through enum Java?

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc. You can iterate the contents of an enumeration using for loop, using forEach loop and, using java.

Can enum have duplicates?

Duplicates in enum type can be done in 2 ways : Duplicate enum members (2 or more members with same name) 2 or more members with same value.

What is EnumSet?

An EnumSet is a specialized Set collection to work with enum classes. It implements the Set interface and extends from AbstractSet: Even though AbstractSet and AbstractCollection provide implementations for almost all the methods of the Set and Collection interfaces, EnumSet overrides most of them.


1 Answers

for (Operations op : Operations.values()) {     ... } 
like image 97
Joonas Pulakka Avatar answered Sep 21 '22 09:09

Joonas Pulakka