0

I would like to implement a Method with a input, which can be "A", "B" or "C". I know how to implement this with a String check, but I don't think its as clean as I need it to be. Is there any way doing this better (With an enum or something like that)?

Example:

private final options = {"A", "B", "C"};
private option;

public void setOption(option o){
   if(this.options.contains(o)){
      this.option = o;
   } else {
      this.option = null;
   }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user111
  • 43
  • 2
  • 6

1 Answers1

0

Use an Enum in combination with a switch statement. If you need to futher process your string, use String.equals(String) to compare your two strings.