字符串的CharAt方法使用long [英] String's CharAt method using long

查看:62
本文介绍了字符串的CharAt方法使用long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在非常大的字符串的特定位置找到字符.但是我无法使用 charAt()方法,因为该范围超出了int的范围.有什么调整吗?

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. Is there a tweak to this?

推荐答案

在Java中,字符串由字符数组支持.数组的理论大小受 int 的最大值限制,因此不可能有超过2个 31 -1个字符的String开头.

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.

这篇关于字符串的CharAt方法使用long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆