You should be able to get a String of length
-
Integer.MAX_VALUE
always 2,147,483,647 (231 – 1)
(Defined by the Java specification, the maximum size of an array, which the String class uses for internal storage)
OR -
Half your maximum heap size
(since each character is two bytes) whichever is smaller.