How many bytes can the string

Hi,

I have the problem to create the String with the lenght longer than 2 MBytes.

For instance :

byte[] b = new byte[10*1024*1024);

........................

........................

len = b.length;

String s = new String(b,0,len);

Any helps are appreciated.

PS: Pls assume b contains a data e.g. 7*1024*1024 and has the length of 7*1024*1024, everthing is ok until the String can not be instanstiated.

Regards

Paulus

[516 byte] By [PaulusL] at [2007-9-26 4:30:01]
# 1
try the StringBuffer-class it is just build for such problems
swingfreak at 2007-6-29 17:42:01 > top of Java-index,Archived Forums,Java Programming...
# 2

> I have the problem to create the String with the lenght longer than 2 MBytes.

What do you mean - what kind of problem? This works just fine:public class test {

public static void main(String args[]) {

byte[] b = new byte[10 * 1024 * 1024];

for (int j = 0; j < b.length; j++) {

b[j] = 97;

}

String s = new String(b) + "b";

System.out.println(s);

}

}

(although running did require setting the max. heap size bigger... :)

jsalonen at 2007-6-29 17:42:01 > top of Java-index,Archived Forums,Java Programming...