As we all know, in Java, the expression in the switch statement must be an integer or operator type. strings are used for branching and can only be opportunistic.
The first key is to use the String hasCode to obtain the String hash code. The hash code algorithm is as follows:
S [0] * 31 ^ (n-1) + s [1] * 31 ^ (n-2) +... + s [n-1]
Therefore, the hash codes of two different strings are almost different (they may be the same. If you need to study them in depth, study it yourself, huh, huh ),
HasCode returns an int value. OK. We will use this as the constant value after case.
The second key is that this hasCode cannot be used directly. You can only manually obtain the string hash code in advance, declare a final int variable, and use this as a case.
In this way, the expression after your switch can use XXX. hasCode, And the defined constant value is used in case.
Isn't it a little troublesome? No way. It can only be achieved in a single bend.