This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Length of a String

 
Emil Karlsson
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, a short question.
Is there any maxlength for a String?
/Emil
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Integer.MAX_VALUE
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
/Emil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic