title: Is remove() faster than get() in HashMap?
body: <p>I have written a benchmark for <code>get</code> and <code>remove</code> of <code>HashMap</code> as below:</p>
  
  <pre><code>@BenchmarkMode(Mode.AverageTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public class HashMapBenchmark {
  
    @State(Scope.Benchmark)
    public static class Mystate {
        HashMap&lt;String,String&gt; hashmapVar = new HashMap&lt;String,String&gt;();
        String key0 = "bye";
  
        @Setup(Level.Iteration)
        public void setup(){
            hashmapVar.put(key0,"bubye");
        }
    }
  
    @Benchmark
    public void hashmapGet(Mystate state ,Blackhole bh) {
        bh.consume(state.hashmapVar.get(state.key0));
    }
  
    @Benchmark
    public void hashmapRemove(Mystate state ,Blackhole bh) {
        bh.consume(state.hashmapVar.remove(state.key0));
    }
  }
  </code></pre>
  
  <p>It produces this result:</p>
  
  <pre><code>Benchmark                             Mode  Samples  Score  Score error  Units
  c.b.HashMapBenchmark.hashmapGet       avgt       60  6.348        0.320  ns/op
  c.b.HashMapBenchmark.hashmapRemove    avgt       60  5.180        0.074  ns/op
  </code></pre>
  
  <p>As per the result, <code>remove()</code> is slight faster than <code>get()</code>.
  Even to remove an element, first it has to retrieve the element, doesn't it?</p>
  
  <p>How can <code>remove()</code> be faster? Or am I missing something?</p>
  
  <p><strong>Update</strong>
  After using the latest JMH (1.11.3) and here is the result:</p>
  
  <pre><code>Benchmark                                 Mode  Cnt  Score   Error  Units
  HashMapBenchmark.hashmapGet               avgt   60  9.713 ± 0.277  ns/op
  HashMapBenchmark.hashmapRemove            avgt   60  7.677 ± 0.166  ns/op
  </code></pre>