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:
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?
Strings do not equal enums. You could write something like g.name().equals("group_certification_staff")
to see if it has the same name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.