0

I have a one-character string ch, and I want to return some integer depending of its value. I managed to make this if else statement using the regular expressions method .regex:

if (ch.matches("[AEILNORSTU]")){
            return 1;
        } else if (ch.matches("[DG]")){
            return 2;
        } else if (ch.matches("[BCMP]")){
            return 3;
        } else if (ch.matches("[FHVWY]")){
            return 4;
        } else if (ch.matches("[K]")){
            return 5;
        } else if (ch.matches("[JX]")){
            return 8;
        } else if (ch.matches("[QZ]")){
            return 10;
        } else return 0;

Is there a switch equivalent to this?

Guilherme
  • 322
  • 1
  • 11

0 Answers0