当前位置:网站首页>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 .
边栏推荐
- C. Fishingprince Plays With Array
- At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
- 安科瑞高等学校校园建筑节能监管系统建设
- Introduction to opencv (I): image reading and display
- Simple application of generating function
- [notes] polygon mesh processing learning notes (10)
- Cadence physical library lef file syntax learning [continuous update]
- Experiment 3 remote control
- Construction of module 5 of actual combat Battalion
- Deep learning - networks in networks and 1x1 convolution
猜你喜欢
![July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)](/img/37/ae0f7ca03ef564b029c9c709779231.jpg)
July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)

vulfocus入门靶机

National technology n32g45x series about timer timing cycle calculation

Analysis of cross clock transmission in tinyriscv
![November 16, 2021 [reading notes] - macro genome analysis process](/img/c4/4c74ff1b4049f5532c871eb00d5ae7.jpg)
November 16, 2021 [reading notes] - macro genome analysis process

December 4, 2021 - Introduction to macro genome analysis process tools

1162 Postfix Expression
![[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
![Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]](/img/30/375860665aa1cc761adffc0e782744.jpg)
Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]

Opencv4.2.0+vs2015 configuration
随机推荐
Introduction notes to pytorch deep learning (10) neural network convolution layer
JS代码案例
ACM. HJ48 从单向链表中删除指定值的节点 ●●
November 16, 2021 [reading notes] - macro genome analysis process
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
2021.11.20 [reading notes] | differential variable splicing events and DTU analysis
Deep learning - bounding box prediction
期末複習-PHP學習筆記5-PHP數組
25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了
Deep learning - embedding matrix and learning word embedding andword2vec
Development technology sharing of Jingtan NFT digital collection system
Cadence innovus physical implementation series (I) Lab 1 preliminary innovus
Why don't you know what to do after graduation from university?
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
Want to change careers, but don't know what to do? This article is written for you who are confused
Recurrence relation (difference equation) -- Hanoi problem
深度学习——使用词嵌入and词嵌入特征
How to handle the expired data of redis and what are the elimination mechanisms?
July 30, 2021 [wgs/gwas] - whole genome analysis process (Part I)
期末复习-PHP学习笔记5-PHP数组