当前位置:网站首页>Map to sort
Map to sort
2022-06-12 06:54:00 【ldj2020】
package com.jt.test;
import java.util.*;
/**
* @Author: ldj
* @Date: 2022/02/16/11:39
* @Description: Yes map Sort
*/
public class SplicingXml {
public static void main(String[] args) {
Map<String, String> dateMap = new HashMap<>();
dateMap.put("1 God ", "day1");
dateMap.put("5 God ", "day5");
dateMap.put("4 God ", "day4");
dateMap.put("2 God ", "day2");
dateMap.put("3 God ", "day3");
//------------------ Yes key Key values are sorted in ascending dictionary order ---------------------
Set<String> keySet = dateMap.keySet();
List<String> list = new ArrayList<>(keySet);
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i) + " => " + dateMap.get(list.get(i)));
}
//------------------ Traverse in insertion order (" Orderly map")---------------------------
Map<String, String> linkedHashMap = new LinkedHashMap();
linkedHashMap.put("A", "a");
linkedHashMap.put("B", "b");
linkedHashMap.put("D", "d");
linkedHashMap.put("F", "f");
linkedHashMap.put("C", "c");
// Use foreach Traverse ( Most succinct , Low performance requirements , recommend )
linkedHashMap.forEach((k, v) -> System.out.println(k + ":" + v));
// Use iterators to traverse 1 ( Efficient )
Iterator<Map.Entry<String, String>> entries = linkedHashMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, String> entry = entries.next();
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + ":" + value);
}
// Use iterators to traverse 2 ( Low efficiency )
Iterator<String> iterator = linkedHashMap.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
String value = linkedHashMap.get(key);
System.out.println(key + ":" + value);
}
}
}
边栏推荐
- Junior high school education, less than 3k, to 30k+ monthly salary, how wonderful life is without restrictions
- leetcode.39 --- 组合总和
- C language pointer
- Throw away the ugly toast. The movable toast is more interesting
- 8 IO Library
- Postman splice replacement parameter loop call interface
- LeetCode-1303. Team size
- CL210OpenStack操作的故障排除--章節實驗
- Network packet loss troubleshooting
- 6 functions
猜你喜欢

库里扛起了勇士对凯尔特人的第四场

【图像去噪】基于高斯滤波、均值滤波、中值滤波、双边滤波四种滤波实现椒盐噪声图像去噪附matlab代码

SQL language

企业微信官方 加解密库 PHP7版本报错 mcrypt_module_open 未定义方法 并且被PHP抛弃 解决方法使用 openssl解决

Vscode common plug-ins

sql server 2019安装出现错误,如何解决

libprint2

SQL injection read / write file
![leetcode:890. Find and replace mode [two dict records set]](/img/a8/e1ea743bbd8d2aca4de3e3ac3b4ac3.png)
leetcode:890. Find and replace mode [two dict records set]

Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
随机推荐
leetcode:890. 查找和替换模式【两个dict记录双射(set)】
Computer composition and design work06 - based on MIPS
I met 15 people recently and found that I couldn't answer the basic question of this test
“我被大厂裁员了”
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
esp32 hosted
A journey of database full SQL analysis and audit system performance optimization
Dépannage de l'opération cl210openstack - chapitre expérience
It only takes 10 minutes to understand the underlying principle of NiO
leetcode. 39 --- combined sum
CL210OpenStack操作的故障排除--章節實驗
The second revolution of reporting tools
六月集训 第二天——字符串
leetcode:剑指 Offer 60. n个骰子的点数【数学 + 层次dp + 累计贡献】
Vscode Common plug - in
d中的解耦
June 9th training day - bit operation
The principle of SQL injection is to build sqli labs, and SQL injection is simple and practical
LeetCode-1350. Invalid students
2021 robocom world robot developer competition - undergraduate group (Preliminary)