当前位置:网站首页>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 .
边栏推荐
- 直击产业落地 | 飞桨重磅推出业界首个模型选型工具
- Combinatorial mathematics Chapter 2 Notes
- 期末複習-PHP學習筆記5-PHP數組
- More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
- 深度学习——GRU单元
- JS code case
- [flower carving experience] 12 build the Arduino development environment of esp32c3
- Final review -php learning notes 1
- November 19, 2021 [reading notes] a summary of common problems of sneakemake (Part 2)
- Deep learning - goal orientation
猜你喜欢
Introduction notes to pytorch deep learning (10) neural network convolution layer
Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]
Simple application of generating function
深度学习——循环神经网络
鲸探NFT数字臧品系统开发技术分享
深度学习——序列模型and数学符号
December 19, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5 advanced database search)
Deep learning - LSTM
Final review -php learning notes 1
Want to change careers, but don't know what to do? This article is written for you who are confused
随机推荐
6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了
Construction of module 5 of actual combat Battalion
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)
深度学习——GRU单元
深度学习——语言模型和序列生成
Simple application of generating function
Halcon12+vs2013 C # configuration
深度学习——LSTM
Do you know the IP protocol?
Introduction notes to pytorch deep learning (10) neural network convolution layer
An example of a single service in a cloud project driven by a domain
Cadence physical library lef file syntax learning [continuous update]
Deep learning - LSTM
Final review -php learning notes 1
深度学习——特征点检测和目标检测
深度学习——循环神经网络
【Tensorflow-gpu】window11下深度学习环境搭建
Combinatorial mathematics Chapter 1 Notes
Efga design open source framework openlane series (I) development environment construction