title: Java 1.8: any way to O(1) an object in a LinkedList<> with remove( object )?
body: <p>I think not, so what I've done is to manually write a double-linked list mapping iOrderID to Order, and support it with a HashMap.  I use the HashMap to find the order, and when I do, I can de-link it instantly.</p>
  
  <pre><code>class Order {
      Product product;
      Order orderPrev, orderNext;
  
      // The business fields I need are here.
  }
  
  Map&lt;Integer, Order&gt; maporder = new HashMap&lt;&gt;();
  </code></pre>
  
  <p>Then to delete:</p>
  
  <pre><code>void Delete( int iOrderID ) {
      Order order = maporder.get( iOrderID );
  
      if ( order == null ) {
          LogError( "order not found" );
          return false;
      }
  
      maporder.remove( order.iOrderID );
  
      if ( orderPrev != null ) {
          orderPrev.orderNext = orderNext;
      } else {
          product.orderHead = orderNext;
      }
  
      if ( orderNext != null ) {
          orderNext.orderPrev = orderPrev;
      } else {
          product.orderTail = orderPrev;
      }
  </code></pre>
  
  <p>(Note that like the top 20 pages you find on Google that summarize O() for various options report <code>remove()</code> as O(1) but I'm positive they're all talking about <code>removeFirst()</code> and maybe <code>removeLast()</code>.)</p>