什么是数据的一个字符串可以容纳在java中的最高金额? [英] What is the maximum amount of data that a String can hold in java?

查看:124
本文介绍了什么是数据的一个字符串可以容纳在java中的最高金额?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能是一个非常noobish qustion要求,但我没有发现任何好的可靠的资源在那里我能得到这个信息。

I know this may be a really noobish qustion to ask but I found no good reliable resource where I can get this info.

在一个Android应用程序,我想仅通过继续与更多的数据追加在一个字符串保存数据。最后,当用户关闭应用程序或打一个保存按钮,我登录到一个数据.csv文件。

In an Android application, I'm trying to hold data in a String by just continuing to append it with more data . And finally when the user closes the application or hits a "save button", I log it into a data .csv file.

我想知道有多少数据可以在Java简单的字符串保持?,那么该应用程序并不重要,如果字符串数据类型用完分配的内存崩溃。 BTW我试图压力测试我的应用程序,它似乎运行正常,无论我有多少数据存储在一个字符串。

I want to know how much data can a simple String hold in java?, So that the app does not crash if the String datatype runs out of the memory allocated. BTW I have tried to stress test my application, and it seems to run fine no matter how much data I store in one string.

平硐

推荐答案

看到的字符串长度()方法返回一个int值,最大将由该方法要返回的长度将是Integer.MAX_VALUE的,这是2 ^ 31 - 1(。或约2十亿)

Seeing as the String class' length() method returns an int value, the maximum length that would be returned by the method would be Integer.MAX_VALUE, which is 2^31 - 1 (or approximately 2 billion.)

所以,你可以有2,147,483,647个字符的字符串,在理论上。我不认为你应该需要远不止这些。

So you can have a String of 2,147,483,647 characters, theoretically. I don't think you should need much more than that.

不过,正如@TedHopp指出评价和张贴在他的回答中,Android系统的限制你的堆空间,会低至16 MB。所以,你永远不会实际能够达到的理论极限,并且将最多用在4-64万元字符范围内的某处的字符串。

However, as @TedHopp has pointed out in the comments and posted in his answer, the Android system limits your heap space, going as low as 16 MB. Therefore, you'll never practically be able to reach the theoretical limit, and will max out with a String somewhere in the 4-64 million character range.

这篇关于什么是数据的一个字符串可以容纳在java中的最高金额?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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