Java IdentityHashMap put()方法与示例

IdentityHashMap类的put()方法 (IdentityHashMap Class put() method)

  • put() method is available in java.util package.

    put()方法在java.util包中可用。

  • put() method is used to set the given value element (val_ele) with the given key element (key_ele) when no value element associated previously with the given key otherwise it replaces the old value element with the given new value element (val_ele) for the given key element (key_ele) when any value element associated with the given key previously.

    当以前没有与给定键相关联的值元素时,使用put()方法将给定值元素(val_ele)设置为给定键元素(key_ele),否则将旧值元素替换为给定新值元素(val_ele)当先前与给定键关联的任何值元素时,给定键元素(key_ele)。

  • put() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    put()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • put() method does not throw an exception at the time of replacing the value element if exists.

    put()方法在替换value元素(如果存在)时不会引发异常。

Syntax:

句法:

    public Value put(Key key_ele, Value val_ele);

Parameter(s):

参数:

  • Key key_ele – represents the key element with which the given value is to be linked.

    Key key_ele –表示与给定值链接的键元素。

  • Value val_ele – represents the value element to be linked with the given key element (key_ele).

    值val_ele –表示要与给定键元素(key_ele)链接的value元素。

Return value:

返回值:

The return type of the method is Value, it returns the old value element linked with the given key element (key_ele) when exists otherwise it returns null.

该方法的返回类型为Value ,如果存在则返回与给定键元素(key_ele)链接的旧value元素,否则返回null。

Example:

例:

// Java program to demonstrate the example 
// of Value put(Key key_ele, Value val_ele)
// method of IdentityHashMap 
import java.util.*;
public class PutOfIdentityHashMap {
public static void main(String[] args) {
// Instantiates a IdentityHashMap object
Map < Integer, String > map = new IdentityHashMap < Integer, String > ();
// By using put() method is to add
// key-value pairs in a IdentityHashMap
map.put(10, "C");
map.put(20, "C++");
map.put(50, "JAVA");
map.put(40, "PHP");
map.put(30, "SFDC");
// Display IdentityHashMap
System.out.println("IdentityHashMap: " + map);
// By using put() method is to
// replace the existing value associated
// for the given key element with the
// new value element
map.put(50, "Microservices");
// Display Modified IdentityHashMap
System.out.print("IdentityHashMap: " + map);
}
}

Output

输出量

IdentityHashMap: {20=C++, 40=PHP, 50=JAVA, 30=SFDC, 10=C}
IdentityHashMap: {20=C++, 40=PHP, 50=Microservices, 30=SFDC, 10=C}

翻译自: https://www.includehelp.com/java/identityhashmap-put-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544596.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

全球六大国际域名解析量统计报告(6月25日)

IDC评述网&#xff08;idcps.com&#xff09;06月29日报道&#xff1a;根据DailyChanges公布的实时数据显示&#xff0c;在2015年6月25日&#xff0c;全球六大国际域名解析量总量持续攀升至153,246,819个&#xff0c;环比6月16日&#xff0c;净增46,078个&#xff0c;涨幅增大3…

Windows 创建符号链接

一、场景分析 1.环境变量 在Windows系统配置 环境变量 的时候&#xff0c;经常会遇到以下 路径 情况&#xff1a; C:\Program Files C:\Program Files (x86)\Common Files2.异常情况 这种路径中&#xff0c;存在空格字符&#xff0c;在一些程序调用时&#xff0c;可能出现异…

1.3w字,一文详解死锁!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone死锁&#xff08;Dead Lock&#xff09;指的是两个或两个以上的运算单元&#xff08;进程、线程或协程&#xff09;&#xff0c;都在等待…

Java Dictionary elements()方法与示例

字典类的elements()方法 (Dictionary Class elements() method) elements() method is available in java.util package. elements()方法在java.util包中可用。 elements() method is used to get the elements of an Enumeration in this dictionary. elements()方法用于获取此…

PHP与ThinkPHP读写文件

2019独角兽企业重金招聘Python工程师标准>>> 使用php将数据写入到指定的文件 $str"<?php return".var_export($phiz,true)."?>"; file_put_contents(./Data/phiz.php); 使用php读取指定的文件 …

软件版本号设置规则及示例

一、版本号设置规则 ABC客户端 版本说明书 [版本命名规则] 如&#xff1a;1.0.0.0 位数名称描述情景第一位主版本重大修改&#xff0c;重写或里程碑[里程碑] [重大更新]第二位次版本显著增强、功能变更较多[新增功能] [删减功能]第三位生成号功能变更&#xff0c;局部修正较多…

【图解】透彻Java线程状态转换

大家好&#xff0c;我是阿星&#xff0c;好久不见&#xff0c;欢迎来到Java并发编程系列番外篇线程状态转换&#xff0c;内容通俗易懂&#xff0c;请放心食用。线程状态先来个开场四连问Java线程状态有几个&#xff1f;Java线程状态是如何转换&#xff1f;Java线程状态转换什么…

Java Byte类的hashCode()方法及示例

短类hashCode()方法 (Short class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return hashcode of the Byte object. hashCode()方法用于返回Byte对象的哈希码。 hashCode()…

CentOS7安装Hadoop2.7完整流程

2019独角兽企业重金招聘Python工程师标准>>> 1、环境&#xff0c;3台CentOS7&#xff0c;64位&#xff0c;Hadoop2.7需要64位Linux&#xff0c;CentOS7 Minimal的ISO文件只有600M&#xff0c;操作系统十几分钟就可以安装完成&#xff0c; Master 192.168.0.182 Slav…

获取外网IP地址API

1、获取外网IP地址 地址&#xff1a; http://pv.sohu.com/cityjson?ieutf-8 返回结果&#xff1a; var returnCitySN {"cip": "39.***.***.***", "cid": "370000", "cname": "山东省"};2、获取IP地址详细信…

如果不这样用,Nacos也有安全问题!

前言配置管理作为软件开发中重要的一环&#xff0c;肩负着连接 代码和环境的职责&#xff0c;能很好的分离开发人员和维护人员的关注点。Nacos 的配置管理功能就很好地满足了云原生应用对于配置管理的需求&#xff1a;既能做到配置和代码分离&#xff0c;也能做到配置的动态…

java中intvalue_Java Byte类intValue()方法的示例

java中intvalue字节类intValue()方法 (Byte class intValue() method) intValue() method is available in java.lang package. intValue()方法在java.lang包中可用。 intValue() method is used to return the value denoted by this Byte object converted to type int (by c…

python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑

python3.4学习笔记(八) Python第三方库安装与使用&#xff0c;包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件?当我们点开下载页时, 一般会看到以下几种格式的文件: msi, egg, whlmsi文件:Windows系统的安装包, 在Window…

Java BigDecimal toString()方法与示例

BigDecimal类toString()方法 (BigDecimal Class toString() method) toString() method is available in java.math package. toString()方法在java.math包中可用。 toString() method is used to represent string denotation of this BigDecimal with the help of scientific…

聊聊Spring事务失效的12种场景,太坑了

前言对于从事java开发工作的同学来说&#xff0c;spring的事务肯定再熟悉不过了。在某些业务场景下&#xff0c;如果一个请求中&#xff0c;需要同时写入多张表的数据。为了保证操作的原子性&#xff08;要么同时成功&#xff0c;要么同时失败&#xff09;&#xff0c;避免数据…

centos6中三台物理机配置nginx+keepalived+lvs

以下只是简单的安装配置&#xff0c;并没有测试这套负载&#xff0c;各种参数大家可以自己测试vip&#xff1a;10.0.50.170lvs server&#xff1a;10.0.50.183real server&#xff1a;10.0.50.184/185183/184/185同步时间&#xff0c;并且安装nginx# ntpdate time.nist.gov# yu…

python整数转换字符串_Python | 将字符串转换为整数列表

python整数转换字符串Given a string with digits and we have to convert the string to its equivalent list of the integers in Python. 给定一个带有数字的字符串&#xff0c;我们必须将该字符串转换为Python中与之等效的整数列表。 Example: 例&#xff1a; Input:str1…

什么是可中断锁?有什么用?怎么实现?

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone在 Java 中有两种锁&#xff0c;一种是内置锁 synchronized&#xff0c;一种是显示锁 Lock&#xff0c;其中 Lock 锁是可中断锁&#xff…

android开发,设置listview的高度无效

一般是在item的layout中设置高度 android:layout_height"100dp" 但是发现这样后无效&#xff0c;因此找到解决办法&#xff0c;如下&#xff1a; android:minHeight"100dp"

10个经典又容易被人疏忽的JVM面试题

前言整理了10个经典又容易被疏忽的JVM面试题&#xff0c;谢谢阅读&#xff0c;大家加油哈.1. 对象一定分配在堆中吗&#xff1f;有没有了解逃逸分析技术&#xff1f;「对象一定分配在堆中吗&#xff1f;」 不一定的&#xff0c;JVM通过「逃逸分析」&#xff0c;那些逃不出方法的…