当前位置:网站首页>Review of three traversal methods of map
Review of three traversal methods of map
2022-07-25 06:12:00 【Eyes of years】
Map Three traversal methods of
import java.util.*;
/** *Map Traverse * Collection<V> values() Returns the... Of the value contained in this map Collection aggregate . * Set<K> keySet() Get all key, according to key obtain value * Set<Map.Entry<K,V>> entrySet() * K getKey() Return the key corresponding to this entry . * V getValue() * */
public class MapOf_bianli {
public static void main(String[] args) {
Map<String,Integer> map1=new HashMap<>();
map1.put(" Zhang Zetian ",25);
map1.put(" Liu Yifei ",26);
map1.put(" Faye Wong ",46);
map1.put(" Nicholas Tse ",28);
// Traversal methods 1. Use values() Method variable mapping ---> Collection<V> values() Returns the... Of the value contained in this map Collection View .
Collection<Integer> col=map1.values();
for (Integer vals:col){
System.out.println(vals);
}
// Traversal methods 2. Set<K> keySet() Get all key, according to key obtain value
Set<String> set=map1.keySet();
// To obtain a set aggregate , Use enhancements foreach and Iterator
Iterator it=set.iterator();// Get one Iterator object
while(it.hasNext()){
System.out.println(map1.get(it.next()));
}
/** Traversal methods 3. Set<Map.Entry<K,V>> entrySet() K getKey() Return the key corresponding to this entry . V getValue() */
Set<Map.Entry<String,Integer>> entries=map1.entrySet();
// call map A collection of entrySet() Method returns Set aggregate , The type is Map.Entry<String,Integer>
for (Map.Entry<String,Integer> ent:entries){
// Use enhancements for Loop through each pair of key value pair elements
System.out.println(ent.getKey()+"----->"+ent.getValue());
}
}
}
边栏推荐
- Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
- How to start if you want to be a product manager?
- Big talk · book sharing | Haas Internet of things device cloud integrated development framework
- [C language] in depth understanding of pointers and arrays (phase I)
- In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
- Detailed annotation and analysis of start.s of uboot
- VIM configuring golang development environment
- Seekbar属性参考
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- 【每日一练】day(14)
猜你喜欢

(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)

【Unity3D】UGUI回调函数

Design of automatic machine dot drawing script based on C language
![[unity3d] ugui callback function](/img/6f/312e7f2cf76fa932e66c5ba0737219.png)
[unity3d] ugui callback function

(2022 Niuke multi school) D-Link with game glitch (SPFA)

Siggraph 2022 -- rendering iridescent rock dove neck feathers

四、MFC工具栏、运行时类信息机制、运行时创建机制

Please stop using system The currenttimemillis() statistical code is time-consuming, which is really too low!

【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口

基于ISO13209(OTX)实现EOL下线序列
随机推荐
R language uses wilcox.test function to perform Wilcox signed rank test to obtain confidence interval of population median (set conf.level parameter to specify confidence level and size of confidence
[C language] in depth understanding of pointers and arrays (phase I)
(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
VBA common objects
MFC IniFile Unicode mode reading method
A little experience about von Mises distribution
Dry goods | training AI model can't find data? Collect 20 selected open source communities!
Multithreading programming under Win32 API
Date (day 76)
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
(Niuke multi school I in 2022) i-chiitoitsu (expected DP)
Daily question brushing record (XXVIII)
Singing "Seven Mile fragrance" askew -- pay tribute to Jay
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动
(牛客多校二)G-Link with Monotonic Subsequence(构造题)
Interlocked atom access series of functions
Define usage method and template
深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
R language uses LM function to build multiple linear regression model and write regression equation according to model coefficient
Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network