Results 1 to 6 of 6

Thread: Limit of String

  1. #1
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default Limit of String

    Can any one tell me the size limit of String object? How much it can hold?

    Java Code:
    String myString = “text goes here”;

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Since Java used 16 bits unicode, 1 char = 2 bytes. So the string size would be Integer.MAX_VALUE. But I'm wired there, because available memory can cause on it. ;)

    Actually you don't want to worried about the maximum length of a string. You always get a out of memory exception before you pass the maximum length of a string. :p


  3. #3
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default

    Thanks for your help.
    Actually I am parsing a file and placing it into a String and want to know if it s a good idea to get it into String as OutOfMemory exception will create problems for me.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What kind of file it is. Can't you read line by line to your application, I hope a line wont be too long to give an exception on the length of a string.

  5. #5
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default

    Its a simple ASCII file but the lines are too big. I am not sure about the size but it varies with the file.

    Surely, I am reading the file line by line in to String. Only thing that worries me is the line can be too much for the String. I might come up with an example to this.

    Thanks.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Actually you can do more other things on this. Read the specific length of a line to a string. Later you can merge them. But actually it is not that much easy. Because after merging the strings it should gives the exact output. You have think about a logic your self.:p

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2008, 07:30 AM
  2. PM Inbox Limit Increased
    By JavaBean in forum Suggestions & Feedback
    Replies: 7
    Last Post: 01-17-2008, 08:48 PM
  3. Replies: 0
    Last Post: 11-20-2007, 04:59 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:29 AM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •