Beginner
Beginner

Reputation: 313

How to get the Value from Enum in java


How to get the value Apple if I pass A ...

public enum Enumtype {
  A("Apple"), B("Ball"), C("Cat");

  private String value;

  private Enumtype(String value) {
      this.value = value;
  }
}

Upvotes: 0

Views: 85

Answers (1)

maximede
maximede

Reputation: 1823

you need to add a getter in your enum :

public String getValue(){
    return this.value;
}

Upvotes: 0

Related Questions