<div dir="ltr"><div>To try to loop back on my original point... <br></div><div><br></div><div>The "underlying problem" that I think should be addressed by some new internal class (or suite of classes) is the "array builder" problem. This is where you're doing "append, append, append, ..., use read-only thereafter".</div><div><br></div><div>Currently people use ArrayList for that, or for primitive arrays, homebrew it with System.arraycopy()  - or maybe I'm missing something like this that already exists?</div><div><br></div><div>I would like to see JDK standard "array builders" for primitive types and reference types that use fixed sized (power-of-two) segments internally. These can be internal classes for now.</div><div><br></div><div>Then the faster ByteArrayOutputStream becomes just a wrapper around "ByteArrayBuilder" or whatever we call it.</div><div><br></div><div>This is all just my opinion, I'm curious if others perceive the same gap that I do?</div><div><br></div><div>-Archie</div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Apr 11, 2025 at 10:15 AM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Fri, Apr 11, 2025 at 8:11 AM Engebretson, John <<a href="mailto:jengebr@amazon.com" target="_blank">jengebr@amazon.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>





<div lang="EN-US">
<div><p class="MsoNormal">It seems like a good general-purpose list but I wouldn’t recommend it as a direct replacement for either ArrayList or LinkedList; in the former case the risk is slower random accesses, and in the latter the risk is to head modifications.</p></div></div></div></blockquote><div><br></div>Interesting results. However I don't think comparing this to both ArrayList and LinkedList is really fair. Developers choose an implementation based on how they know they are going to use it: If they are just adding stuff, they choose ArrayList. If they know they need to insert/remove in the middle, they choose LinkedList. If they need to add/remove from both ends, they choose ArrayDeque. Etc.</div><div class="gmail_quote"><br></div><div class="gmail_quote">So the optimal design changes depending on which "flavor" of list usage the developer is implying when they choose some implementation class.</div><div class="gmail_quote"><br></div><div class="gmail_quote">E.g., if you wanted to target the "ArrayList flavor', then you'd use fixed size, power-of-two segments. Then get() remains constant time, and insert and remove remain as painfully slow as ever, but the common "list builder" usage pattern of "append, append, append, ..., use read-only thereafter" gets a lot faster.</div><div class="gmail_quote"><br></div><div class="gmail_quote">OTOH variable-sized chunks makes lots of sense for the "LinkedList" flavor. In fact you could have a LinkedList<T> that just uses an ArrayList<ArrayDeque<T>> internally :)</div><div class="gmail_quote"><br></div><div class="gmail_quote">-Archie</div><div class="gmail_quote"><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div><div><br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>