当前位置:网站首页>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());
}
}
}
边栏推荐
- [C language] in depth understanding of pointers and arrays (phase I)
- VIM configuring golang development environment
- Typedef usage and template
- 机器学习 Keras拟合正弦函数
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- Daily question brushing record (XXVIII)
- 基于ISO13209(OTX)实现EOL下线序列
- VSCode 如何开启多个终端?如何横向显示?
- Date (day 76)
- Unity 模型简化/合并 一键式插件
猜你喜欢

Unity Animator动画与状态机
![[C language] in depth understanding of pointers and arrays (phase I)](/img/4b/26cf10baa29eeff08101dcbbb673a2.png)
[C language] in depth understanding of pointers and arrays (phase I)

Prometheus operator configures promethesrule alarm rules

Blocking Queue Analysis
![[unity3d] ugui callback function](/img/6f/312e7f2cf76fa932e66c5ba0737219.png)
[unity3d] ugui callback function

How to play a data mining game entry Edition

10. Rendering Basics

Xiaomi 12s UTRA Leica watermark generation online tool

剑指 Offer 45. 把数组排成最小的数

新时代生产力工具——FlowUs 息流全方位评测
随机推荐
Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
R language uses data.table function to create data.table data (use: operator to create continuous numeric vector)
Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
Idea commonly used 10 shortcut keys
VBA common objects
机器学习 Keras拟合正弦函数
Promise implementation
有什么能在网上挣钱的项目啊?做自媒体靠谱吗?
Unity 模型简化/合并 一键式插件
leetcode/ 前 n 个数字二进制中 1 的个数
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
GF Securities online account opening? Is it safe?
MFC IniFile Unicode mode reading method
Unity Animator动画与状态机
Xiaomi 12s UTRA Leica watermark generation online tool
剑指 Offer 32 - I. 从上到下打印二叉树
Amazoncaptcha 95%成功率绕过亚马逊IP验证码
Sword finger offer 54. the k-th node of the binary search tree
leetcode/整数除法