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
Java IdentityHashMap put()方法与示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
- filepermission java,Java FilePermission getActions()方法与示例
FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...
- java方法参数Bundle,Java ResourceBundle keySet()方法及示例
ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...
- java exec waitfor,Java Process waitFor()方法与示例
流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...
- java arraylist.add(),Java ArrayList add()方法与示例
ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...
- java rollback用法,Java Connection rollBack()方法与示例
回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...
- inputstream 关闭 java,Java ObjectInputStream close()方法与示例
ObjectInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此ObjectInputStream并释放与此流链接的所有系统资源. cl ...
最新文章
- 神器来啦!一键可视化,终于能看懂神经网络到底在干啥了
- 格式化时间中HH:mm:ss与hh:mm:ss的区别
- 基于51单片机的高频频率计的设计
- Lombok 天天用,却不知道它的原理是什么?
- 【设计模式】—— 命令模式Commond
- centos mysql 启动_MYSQL在centos上首次启动
- 使用Spring AOP进行面向方面的编程
- 成功的秘诀是什么_学习编码的10个成功秘诀
- 机器学习理论知识部分--偏差方差平衡(bias-variance tradeoff)
- Python3 爬虫实战 — 豆瓣电影TOP250【requests、Xpath、正则表达式、CSV、二进制数据储存】
- python3-numpy数组广播 和 np.tile 扩展数组
- 随想录(程序语言只是SE的敲门砖)
- 深度解密 Go 语言之基于信号的抢占式调度
- linux nfs用的用户权限,权限 – Linux特定用户安装NFS
- 2015年蓝桥杯省赛C++(A组) 第三题 奇妙的数字
- win系统CH341驱动安装方法
- STC8H8K64U单片机学习-0-宏晶STC官网初探
- 英文打字测试C语言课程设计,语言设计打字练习题库.doc
- chrome插件开发基础以及如何防止劫持
- openstack安装文档
热门文章
- python 除数不能为零的报错有哪些_【社区精选40】Python错误处理及代码调试方法(文末赠书中奖名单)...
- mysql备份服务器中的_使用 Shell 备份远程服务器上的 MySQL 数据库到本机
- linux tips 技巧笔记二
- Rabbit and Grass【博弈】
- PowerDesigner15连接Oracle数据库并导出Oracle的表结构
- linux java 部署 生产环境
- [3/21]Windows Server 2008时钟方面的改进展示
- 公众号 -「前端攻略 开光篇」
- Crazy Drops 3
- Objective-C学习笔记(一)–类