String's CharAt method using long

前端 未结 3 1016
無奈伤痛
無奈伤痛 2021-01-04 17:51

I want to find the character at a particular position of a very large string. However i am unable to use charAt() method because the range exceeds that of int.

相关标签:
3条回答
  • 2021-01-04 18:22

    In Java, Strings are backed by a character array. The theoretical size of an array is limited by the maximum value of int, so it's impossible to have a String with over 231-1 characters to begin with.

    To overcome this issue you can create a string class of your own that uses multiple arrays or strings as storage.

    0 讨论(0)
  • 2021-01-04 18:29

    As the String is internally represented by array of chars its maximal length cannot be bigger than size of int. So in the first place you cannot have String that exceeds range of int.

    0 讨论(0)
  • 2021-01-04 18:32

    Would taking just a shorter substring from the large string and accessing the corresponding position help?

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