title: Java high amount of char[], how to reduce?
body: <p>I believe this garbage is created when I call <code>new String</code> in various places throughout my application. How can I "create" a string without making a new object each time?</p>
  
  <p>The reason for being this garbage-sensitive is because my application <em>cannot</em> create garbage as we need to run close to real-time with the default Java GC.</p>
  
  <pre><code>// you can see I use the same chars array
  public String getB37String() {
      long l = getLong();
      int i = 0;
      while (l != 0L) {
          long l1 = l;
          l /= 37L;
          chars[11 - i++] = validChars[(int) (l1 - l * 37L)];
      }
      return new String(chars, 12 - i, i);
  }
  </code></pre>
  
  <p>And for example using <code>StringBuilder.toString()</code> which uses <code>new String</code> underneath.</p>
  
  <pre><code>// and you can see that I use the same builder
  public String getString() {
      builder.delete(0, builder.length());
      char ascii;
      while (0 != (ascii = (char) getUByte()) &amp;&amp; backing.hasRemaining())
          builder.append(ascii);
      return builder.toString();
  }
  </code></pre>