File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What's the maximum length of 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 "What Watch "What New topic

What's the maximum length of a string?

Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
I want to implement a simple e-mail sender application using Java Mail.
Suppose I am going to make it a web-based application implemented in servlet.
Suppose the web interface has a message text box, in which the user can
enter the e-mail message.
Now here is my question: Suppose the user types in a lengthy text message of size 5K bytes. I am assuming that this size is good enough for my
question. How do I grab such a lengthy text? Can I use String? Like this:
String msg=request.getParameter("emailMessage");
I doubt this will work.
I guess I can do it using BufferedReader, like so:
BufferedReader br=new BufferedReader(new InputStreamReader(;
But, the problem is how can I send the message in the buffer by e-mail?
Thanks a lot.
[ April 01, 2002: Message edited by: Gene Chao ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You mean "How long is a piece of String?"
Sorry, I couldn't resist
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
You might as well just go for the string.
A string can be pretty big. They're basically just over-glorified char[]'s. Since an array's size is of the type int, I'm guessing the maximum size of String is 2,147,483,647 characters. That should be enough to hold 5,000 characters with room to spare.
With the POST http method, a large amount of information can be sent without much trouble. You can upload much bigger files with the good old file upload forms.
String won't be the most efficient method, but I'll get the job done.
[ April 01, 2002: Message edited by: David Weitzman ]
I agree. Here's the link:
subject: What's the maximum length of a string?
jQuery in Action, 3rd edition