How to map character to numeric position in java?

前端 未结 7 1973
忘了有多久
忘了有多久 2020-11-30 06:26

E.g.

  • input: [\'A\', \'Z\', \'F\', \'D\', ...]
  • output: [0, 25, 5, 3, ...]

In C I\'d just subtract the char from \'A\', but I don\'t seem

7条回答
  •  醉话见心
    2020-11-30 06:46

    String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    return alphabet.indexOf( myChar );
    

提交回复
热议问题