HashMap方法之Map.getOrDefault()怎么使用


本篇内容介绍了“HashMap方法之Map.getOrDefault()怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!HashMap getOrDefault(key, defaultValue) method in Java with ExamplesThe getOrDefault(Object key, V defaultValue) method of Map interface, implemented by HashMap class is used to get the value mapped with specified key. If no value is mapped with the provided key then the default value is returned.Syntax:Parameters: This method accepts two parameters:key: which is the key of the element whose value has to be obtained.defaultValue: which is the default value that has to be returned, if no value is mapped with the specified key.Return Value: This method returns value mapped with the specified key, otherwise default value is returned.意思就是当Map集合中有这个key时,就使用这个key值,如果没有就使用默认值defaultValueProgram 1:Output:HashM免费云主机域名ap: {a=100, b=200, c=300, d=400}
Returned Value: 200Program 2:Output:HashMap: {a=100, b=200, c=300, d=400}
Returned Value: 500“HashMap方法之Map.getOrDefault()怎么使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注百云主机网站,小编将为大家输出更多高质量的实用文章!

相关推荐: CentOS6.2下怎么升级安装MySQL5.5

这篇文章主要介绍“CentOS6.2下怎么升级安装MySQL5.5”,在日常操作中,相信很多人在CentOS6.2下怎么升级安装MySQL5.5问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CentOS6.2下怎么升级安装MyS…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 05/28 21:50
下一篇 05/28 21:51

相关推荐