Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Max length for a String?

 
Balamaci Serban
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if Java has a maximum length of characters in a String?
Thanks,!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The length() method returns a signed integer, so that the largest length() value is 2GB. Internally, all the implementations of String I've looked at use an int to keep track of the number of characters, meaning that 2GB is a hard limit. Given that many Java implementations have a heap-size limit somewhat less that 2GB, this is not really a problem!
 
Balamaci Serban
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whew that takes a stone off my chest. Thanks pardner!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic