What is the maximum amount of data that a String can hold in java?
android, java
Solution
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.)
So you can have a String of 2,147,483,647 characters, theoretically. I don't think you should need much more than that.
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.
Problem
I know this may be a really noobish qustion to ask but I found no good reliable resource where I can get this info. 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. 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. Adit