TreeMap中的重复键 [英] Duplicate key in TreeMap

查看:410
本文介绍了TreeMap中的重复键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码用于存储重复键的树形图,它似乎覆盖了现有的代码。

I have the below code for tree map where I store duplicate key and it seems overwrite the existing one.

TreeMap<String, Integer> tm=new TreeMap<>();
tm.put("vivek", 1);
tm.put("vivek", 2);
System.out.println(tm);

打印 {vivek = 2} 所以它意味着地图允许以密钥为基础进行覆盖?

It prints {vivek=2} So it means map allow to overwrite on key basis?

推荐答案

TreeMap #public V put(K key,V value) API说

TreeMap#public V put(K key, V value) API says


将指定值与此映射中的指定键相关联。
如果地图之前包含该键的映射,则会替换旧值。

这篇关于TreeMap中的重复键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆