Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Out of memory exception on stringbuilder.append

800578Jul 4 2008 — edited Jul 4 2008
Hi All,
I am getting out of memory exception at one point of time in the following code. Approximately when number of characters in the builder crosses 1 lakh.
  public static String concatDelimiter(List<String> values, String delimiter) {
    StringBuilder delimitedContent = new StringBuilder();
    delimitedContent.append(" ");
    if(values != null && values.size() > 0) {
      int size = values.size();
      for(int i = 0; i < size; i++) {
        if(i < size - 1) {
          delimitedContent.append(values.get(i) + delimitedContent);
        } else {
          delimitedContent.append(values.get(i));
        }
      }
    }
    return delimitedContent.toString();
  }
Sample Input
*values =* PN, DP, ICT, EC, ECLM, PR, PRD, UCC, CO, IMG, DWC, MC, WEEK, PAN, DAB, IND, CK, DPR, TID, CL1
*delimiter =* ,
Why am I getting the exception? Does it has any size restrictions?
Note: Please dont ask what is the perpose of the method.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2008
Added on Jul 4 2008
5 comments
2,757 views