当前位置:网站首页>Getordefault method of map class
Getordefault method of map class
2022-06-30 08:03:00 【Lafiteeee】
Methods to introduce
java.util.Map<K, V>
public V getOrDefault(Object key, V defaultvalue)
If in map Key found in key The value of the match , Then return the value , Otherwise, return the default value defaultvalue.
================
Usage examples 1:
Array arr There may be duplicate elements in , Will array arr Record the number of occurrences of elements in .
int[] arr = new int[]{
11, 22, 22, 44, 55};
Map<Integer, Integer> map = new HashMap<>();
for(int num : arr){
int temp = map.getOrDefault(num, 0) + 1;
map.put(num, temp);
}
System.out.println(map);
/*Out: <22, 2> <55, 1> <11, 1> <44, 1> */
Pay attention to the brief description when traversing the array for(int num : arr), there num It's every element in the array .
边栏推荐
- 深度学习——GRU单元
- Full stack performance testing theory - Summary
- 1162 Postfix Expression
- 鲸探NFT数字臧品系统开发技术分享
- Deep learning - embedding matrix and learning word embedding andword2vec
- 2021-10-29 [microbiology] qiime2 sample pretreatment form automation script
- Examen final - notes d'apprentissage PHP 5 - Tableau PHP
- tp5设置直接下载文件
- 深度学习——目标定位
- 【花雕体验】14 行空板pinpong库测试外接传感器模块(之一)
猜你喜欢

At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry

深度学习——残差网络ResNets

Construction of energy conservation supervision system for campus buildings of ankery University

深度学习——BRNN和DRNN

深度学习——词汇表征
![2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)](/img/9d/37c531b1b439770f69f715687685f5.jpg)
2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)

亚马逊测评术语有哪些?
![[JUC series] overview of fork/join framework](/img/49/2cadac7818b0c1100539fd32ec0d37.png)
[JUC series] overview of fork/join framework
![[flower carving experience] 13 build the platformio ide development environment of esp32c3](/img/32/2c30afe77bf82774479a671ff16898.jpg)
[flower carving experience] 13 build the platformio ide development environment of esp32c3

【花雕体验】14 行空板pinpong库测试外接传感器模块(之一)
随机推荐
Inversion Lemma
Experiment 2 LED button PWM 2021/11/22
Simple application of generating function
Permutation and combination of probability
深度学习——网络中的网络以及1x1卷积
National technology n32g45x series about timer timing cycle calculation
Miracle Mu server rental selection is real and easy to use, stable and intrusion proof
Lexicographic order -- full arrangement in bell sound
Want to change careers, but don't know what to do? This article is written for you who are confused
F12抓包用于做postman接口测试的全过程解析
mysql无法连接内网的数据库
Final review -php learning notes 1
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
December 4, 2021 [metagenome] - sorting out the progress of metagenome process construction
2021-10-27 [WGS] pacbio third generation methylation modification process
tp5设置直接下载文件
深度学习——语言模型和序列生成
1162 Postfix Expression
Go 数据类型篇之字符串及底层字符类型
2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)