How to map character to numeric position in java?

前端 未结 7 1916
忘了有多久
忘了有多久 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:51

    Use the indexOf method on a String object. For example,

    "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf('F')

    returns 5.

    0 讨论(0)
提交回复
热议问题