Java集合unmodifiableMap()方法及示例
集合类unmodifiableMap()方法 (Collections Class unmodifiableMap() method)
unmodifiableMap() method is available in java.util package.
unmodifiableMap()方法在java.util包中可用。
unmodifiableMap() method is used to get a non-modifiable view of the given Map (map).
unmodifiableMap()方法用于获取给定Map(地图)的不可修改视图。
unmodifiableMap() method is a static method, it is accessible with the class name and if we try to access the method with the class object then also we will not get any error.
unmodifiableMap()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,那么也不会出现任何错误。
unmodifiableMap() method does not throw an exception at the time of returning unmodifiable view of the given map.
返回给定地图的不可修改视图时, unmodifiableMap()方法不会引发异常。
Syntax:
句法:
public static Map unmodifiableMap(Map map);
Parameter(s):
参数:
Map map – represents the map object for which a non-modifiable view is to be retrieved.
地图地图 –代表要检索其不可修改视图的地图对象。
Return value:
返回值:
The return type of this method is Map, it returns an unmodifiable view of the given map.
此方法的返回类型为Map ,它返回给定map的不可修改视图。
Example:
例:
// Java program to demonstrate the example
// of Map unmodifiableMap() method of collections
import java.util.*;
public class UnmodifiableMapOfCollections {public static void main(String args[]) {// Instantiates a linked hashmap object
Map < Integer, String > lhm = new LinkedHashMap < Integer, String > ();
// By using put() method is to add
//objects in a linked hashmap
lhm.put(10, "C");
lhm.put(20, "C++");
lhm.put(30, "JAVA");
lhm.put(40, "PHP");
lhm.put(50, "SFDC");
// Display Linked HashMap
System.out.println("linked hashmap: " + lhm);
// By using unmodifiableMap() method is to
// represent the linked hashmap in unmodifiable view
Map m = Collections.unmodifiableMap(lhm);
//We will get an exception when we
//try to add an object in an unmodifiable map
/* mm.put(60,"COBOL");*/
}
}
Output
输出量
linked hashmap: {10=C, 20=C++, 30=JAVA, 40=PHP, 50=SFDC}
翻译自: https://www.includehelp.com/java/collections-unmodifiablemap-method-with-example.aspx
Java集合unmodifiableMap()方法及示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- java集合代码_Java-集合(示例代码)
一.Java集合框架概述 ●一方面,面向对象语言对事物的体现都是以对象的形式,为了方便对多个对象的操作,就要对对象进行存储.另一方面,使用Array存储对象方面具有一些弊端,而Java集合就像一种容器 ...
- java集合的方法及使用详解
一.java集合的分类及相互之间的关系 Collection接口:向下提供了List和Set两个子接口 |------List接口:存储有序的,存储元素可以重复 |------ArrayList(主要 ...
- java集合list方法吗_关于集合:将List转换为Java集合的最简单方法
在Java中,将EDCOX1的0度转换为EDCOX1×1的最简单的方法是什么? Set foo = new HashSet(myList); @阿什什:这与这个问题完全无关.没有人问如何将空值转换为集 ...
- 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 ...
最新文章
- Linux监控(添加自定义监控项,配置邮件告警)
- 怎么使图表居中显示_【Excel技巧】制作柱形图图表完美呈现百分比,提升您的报表颜值...
- stream pipe的原理及简化源码分析
- CRM product ID format相关配置
- Verification Mind Games---how to think like a verifier像验证工程师一样思考
- RTX5 | 配置文件RTX_Config.h(三)
- linux查看系统版本_Windows电脑如何查看电脑系统位数及版本号
- java 字符串拼接_不能用 + 拼接字符串? 这次我要吊打面试官!
- 《深入理解计算机系统(修订版)》读感
- 数字万用表二极管档测试原理与使用方法--平顶山焦化公司王水成1999年
- BZOJ 3162 独钓寒江雪
- DCOS到底是啥?看完这篇你就懂了
- 消费者太穷不愿买手机?苹果的份额创新高,撕下国产手机遮羞布
- 助力高效办公,TOM企业邮箱网页版全面升级
- SQlServer的日期相减(间隔)dateadd ,datediff 函数
- 单模光电转换器怎么接_光纤收发器怎么连接?光纤收发器连接图解!
- 面向对象,类,属性,方法,创建调用属性方法,有参,无参,变量代码示例
- MySQL字段类型VARCHAR
- 洛谷 P3338【FFT】
- idea使用大全 idea快捷键大全