当前位置:网站首页>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 .
边栏推荐
- November 9, 2020 [wgs/gwas] - whole genome analysis (association analysis) process (Part 2)
- 你了解IP协议吗?
- Final review -php learning notes 1
- Deep learning -- language model and sequence generation
- 深度学习——网络中的网络以及1x1卷积
- Introduction to opencv (II): image color space conversion and image saving
- Palindrome substring, palindrome subsequence
- 2021-10-27 [WGS] pacbio third generation methylation modification process
- Personal blog one article multi post tutorial - basic usage of openwriter management tool
- [flower carving experience] 14 line blank board pingpong library test external sensor module (one)
猜你喜欢
![January 23, 2022 [reading notes] - bioinformatics and functional genomics (Chapter 6: multiple sequence alignment)](/img/48/cfe6ab95b4d4660e3ac3d84ae5303b.jpg)
January 23, 2022 [reading notes] - bioinformatics and functional genomics (Chapter 6: multiple sequence alignment)

Deep learning -- feature point detection and target detection

Simple application of generating function -- integer splitting 2

深度学习——词汇表征

Deep learning - goal orientation

Opencv4.2.0+vs2015 configuration

Permutation and combination of probability

深度学习——目标定位

Palindrome substring, palindrome subsequence

Deep learning - bounding box prediction
随机推荐
ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
Analysis of cross clock transmission in tinyriscv
Want to ask, how to choose securities companies for stock speculation? Is it safe to open an account online?
Wechat applet reports errors using vant web app
Go 数据类型篇之基本数据类型之间的转化
期末複習-PHP學習筆記5-PHP數組
December 19, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5 advanced database search)
深度学习——使用词嵌入and词嵌入特征
Development technology sharing of Jingtan NFT digital collection system
C # about Net cognition
tp5设置直接下载文件
ACM. HJ48 从单向链表中删除指定值的节点 ●●
JS代码案例
How CRM & PM helps enterprises create optimal sales performance
全栈最全性能测试理论-总结
Combinatorial mathematics Chapter 2 Notes
Niuke White Moon race 52
6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了
Examen final - notes d'apprentissage PHP 5 - Tableau PHP
深度学习——循环神经网络