0

I am trying to loop through a HashSet of Enum Objects in Java 8 to see if a value is equal to a specific string. I have tried both equals and == but its not returning true.

HashSet looks like:

enter image description here

I have tried the following:

for(Object g : groups){
                if(g.equals("group_certification_staff")){
                    //Do stuff
                }

for(Object g : groups){
                if(g == "group_certification_staff"){
                    //Do stuff
                }

but it keeps returning false

What am I missing?

Community
  • 1
  • 1

1 Answers1

0

Strings do not equal enums. You could write something like g.name().equals("group_certification_staff") to see if it has the same name.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413