String's CharAt method using long

前端 未结 3 1035
無奈伤痛
無奈伤痛 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.

提交回复
热议问题