当前位置:网站首页>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());
}
}
}
边栏推荐
- VB variable types and control statements (basic)
- What determines the "personality" of AI robots?
- “蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
- Netease game Flink SQL platform practice
- Unity Animator动画与状态机
- 嵌入式c语言开发之宏定义求两个数的最大值的使用技巧
- Unity animator animation and state machine
- Sword finger offer 45. arrange the array into the smallest number
- Promise implementation
- (牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
猜你喜欢

深度解析:2022年最火的商业模式链动2+1,是合法模式吗?

ARM裸板调试之JTAG调试源码级调试
![[daily practice] day (14)](/img/83/d924fa0fc5ae01d151a0880da62f7e.png)
[daily practice] day (14)

Big talk · book sharing | Haas Internet of things device cloud integrated development framework

Req.body in node.express is always undefind

ROI pooling and ROI align

Design of automatic machine dot drawing script based on C language

The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet

【Unity3D】UGUI回调函数

Why is it that all the games are pseudorandom and can't make true random?
随机推荐
10、渲染基础
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
Use abp Zero builds a third-party login module (4): wechat applet development
剑指 Offer 45. 把数组排成最小的数
This is how the permission system is designed, yyds
Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
Unity 模型简化/合并 一键式插件
Matlab drawing example: 5: Biaxial graph
嵌入式c语言开发之宏定义求两个数的最大值的使用技巧
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
VIM configuring golang development environment
What determines the "personality" of AI robots?
SAP FICO section III BDC and ltmc import S4 financial account
(16) [system call] track system call (3 rings)
Some interview questions collected
[unity3d] ugui callback function
[daily practice] day (14)
HTB-Optimum