• Post Reply Bookmark Topic Watch Topic
  • New Topic

How many bytes can a String object contain at maximum?  RSS feed

 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just would like to know if there is a limition for a String object to contain the characters...
 
Joe Ess
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know that there is a hard limit.
When in doubt, test:

Running Java 1.1.4_04 on Win2k it just passed 127k characters while occupying around 6 megs of memory.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an interesting experiment, Joe Ess... ButI guess StringBuffer would hold more than that...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As several methods like length() and indexOf() return ints, the practical limit is Integer.MAX_VALUE; any more and the String interface wouldn't work.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!