Switch ignore case in java 7

前端 未结 3 1414
渐次进展
渐次进展 2020-12-29 18:54

I am doing a POC on Java 7 new features. I have code to use String in switch statement and it works. I want to make it work in case insensitive also. Is there a way to check

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 19:16

    From oracle docs switch with string

    The String in the switch expression is compared with the expressions associated with each case label as if the String#equals method were being used.

    You can use

    switch(s.toUpperCase()){
    ...
    .....
    }
    

    See also

    • String#toUpperCase

提交回复
热议问题