aspose file tools*
The moose likes Beginning Java and the fly likes Length of a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Length of a String" Watch "Length of a String" New topic
Author

Length of a String

Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
Hi, a short question.
Is there any maxlength for a String?
/Emil
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, Integer.MAX_VALUE


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
As you can see Sun source of String (from src.zip)
------------------------------------------------
public final class String
implements java.io.Serializable, Comparable, CharSequence
{
/** The value is used for character storage. */
private char value[];
/** The offset is the first index of the storage that is used. */
private int offset;
/** The count is the number of characters in the String. */
private int count;
/** Cache the hash code for the string */
private int hash = 0;
------------------------------------------------
for allocation characters used char array, so
max length of string is max length of array =
max int value 2**32 = 4GB, but as array index can be used only positive int, so it should be 2Gb.
Emil Karlsson
Ranch Hand

Joined: May 23, 2002
Posts: 63
Thanks a lot!
/Emil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Length of a String
 
Similar Threads
Tech Word Game
date format with MS Access database
How to convert byte array into string array?
WA #1.....word association
ResultSet to Array