Determine if string starts with letters A through I

前端 未结 6 862
北海茫月
北海茫月 2021-01-11 15:30

I\'ve got a simple java assignment. I need to determine if a string starts with the letter A through I. I know i have to use string.startsWith(); but I don\'t want to write,

6条回答
  •  青春惊慌失措
    2021-01-11 16:07

    How about this for brevity?

    if (0 <= "ABCDEFGHI".indexOf(string.charAt(0))) {
        // string starts with a character between 'A' and 'I' inclusive
    }
    

提交回复
热议问题