constant string too long

Is there a limitation on the length of a java.lang.String object ? I could not find any documentation related to this, but when I specify a very long String in my program i get the error :

'constant string too long'

I need to use very long strings .. is there any workaround ?

Pankaj

[310 byte] By [pankajatncsta] at [2007-10-2 13:09:05]
# 1

If you are asking limit on "constant strings" (a.k.a string literals), then refer to JVM spec. second edition

http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html

section 4.10 Limitations of the Java Virtual Machine

The length of field and method names, field and method descriptors, and other constant string values is limited to 65535 characters by the 16-bit unsigned length item of the CONSTANT_Utf8_info structure (?.4.7). Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.

If you need to use longer Strings, you can't have it as a single literal string. You may have to use more than one literal string and concatenate at runtime.

sundararajan.aa at 2007-7-13 10:35:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Thanks, I got it now
pankajatncsta at 2007-7-13 10:35:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...