aspose file tools*
The moose likes Beginning Java and the fly likes Max length for a String? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Max length for a String?" Watch "Max length for a String?" New topic
Author

Max length for a String?

Balamaci Serban
Ranch Hand

Joined: Mar 16, 2005
Posts: 49
Does anyone know if Java has a maximum length of characters in a String?
Thanks,!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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!


[Jess in Action][AskingGoodQuestions]
Balamaci Serban
Ranch Hand

Joined: Mar 16, 2005
Posts: 49
Whew that takes a stone off my chest. Thanks pardner!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Max length for a String?
 
Similar Threads
String.length() returns strange results
NumberFormatException using line.substring
StringOutOfBoundsException
maximum length of String = 32k ?
amount of digits entered(without a tokenizer)....