Switch ignore case in java 7

前端 未结 3 1397
渐次进展
渐次进展 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条回答
  •  隐瞒了意图╮
    2020-12-29 19:17

    no, but you could switch on s.toUpperCase(). so:

    switch (s.toUpperCase()) {
       //same as before
    }
    

    and while we're nitpicking, you better upper-case things in the english locale to avoid issues with turkish

提交回复
热议问题