Why don't Java LinkedHashMaps have an insert() method?
<p>By <code>insert()</code>, I mean <code>insertBefore(key)</code> or <code>insertAfter(key)</code>.</p>

<p>As far as I can make out, inserting a key in the middle of the map can only be achieved by creating a new map and copying across the existing keys and the new key in the correct order.</p>

<p>Considering that LinkedHashMaps are based on double-linked lists, it would have been trivial to implement <code>insertBefore(key)</code> or <code>insertAfter(key)</code>.</p>

<p>Am I missing something here?</p>

<p><strong>Update</strong>
Thanks to everyone who pointed out the the above methods would break the contract of maintaining insertion order.</p>

<p>So let me rephrase the question: does anyone know of a class that would let me do this?</p>

<p>I looked at <code>SortedMap</code> (and its derivatives, including <code>NavigableMap</code>) but I don't want the map to be explicitly sorted. Think of a <code>nodeList</code> in the browser DOM. I just need to be able to insert elements (in this case KV pairs) in any arbitrary order.</p>

<p>Thanks</p>
