title: OutOfMemoryError when joining a list of Strings in Java
body: <p>So. I've tried: </p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  for(String bufferItem: buffer){
      sb.append(bufferItem);
  }
  </code></pre>
  
  <p>and I've also tried:</p>
  
  <pre><code>String.join("\n", buffer)
  </code></pre>
  
  <p>I am joining a large files(under 10GB) in memory on a system with more than 100GB. The following is the stack trace. How can I solve this problem?</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError
      at java.lang.AbstractStringBuilder.hugeCapacity(AbstractStringBuilder.java:161)
      at java.lang.AbstractStringBuilder.newCapacity(AbstractStringBuilder.java:155)
      at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:125)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
      at java.lang.StringBuilder.append(StringBuilder.java:136)
      at java.lang.StringBuilder.append(StringBuilder.java:76)
      at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:484)
      at java.lang.StringBuilder.append(StringBuilder.java:166)
      at java.util.StringJoiner.add(StringJoiner.java:185)
      at java.lang.String.join(String.java:2504)
  </code></pre>