Java HashMap return value not confirming with my understanding of equals and hashcode

后端 未结 4 675
时光说笑
时光说笑 2021-01-23 08:01

The output of the following code sample is:

{1--e=e2, 2--e1=e1}

package com.sid.practice;

import java.util.HashMap;
import         


        
4条回答
  •  生来不讨喜
    2021-01-23 08:06

    The Javadocs for HashMap state for the put method:

    Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.

    Hence, the key is not overwritten, only the value.

提交回复
热议问题