You can use getFruit() == myEnum.APPLE.ordinal()where serial number is the order in which you declare enumerations in your file.
public enum myEnum {
APPLE, ORANGE, BANANA;
}
The ordinal for APPLE in this case is 0, ORANGE is 1, BANANA is 2.
Or you can do the following:
public enum myEnum {
APPLE(1), ORANGE(2), BANANA(3);
private final int i;
private myEnum(int i){
this.i=i;
}
public int getNumber(){
return i;
}
}
getFruit() .