当前位置:网站首页>Traverse map
Traverse map
2022-06-30 06:58:00 【A Xiaoming】
Map Traversal method of collection , You can find , And key The order of insertion is different , There will be sorting effect
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class MapBianli {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
map.put("3", "value3");
map.put("2", "value2");
map.put("1", "value1");
// The first one is : Commonly used , Second value
System.out.println(" adopt Map.keySet Traverse key and value:");
for (String key : map.keySet()) {
System.out.println("key= " + key + " and value= " + map.get(key));
}
// The second kind
System.out.println(" adopt Map.entrySet Use iterator Traverse key and value:");
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
// The third kind of : recommend , Especially when the capacity is large
System.out.println(" adopt Map.entrySet Traverse key and value");
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
}
// A fourth
System.out.println(" adopt Map.values() Traverse all value, But you can't traverse key");
for (String v : map.values()) {
System.out.println("value= " + v);
}
}
}
Ergodic result :
边栏推荐
猜你喜欢
随机推荐
阿里云买的40G高效云盘挂载只有20G
How to convert XML to JSON
Performance comparison of random network, scale-free network, small world network and NS small world matlab simulation
SOC_ SD_ CLK
Joseph problem C language
RT thread Kernel Implementation (VI): time slice
MySQL Optimization: from more than ten seconds to 300 milliseconds
Cmake post makefile:32: * * * missing separator Stop.
SOC_ AHB_ SD_ IF
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
Never forget the original intention, and be lazy if you can: C # operate word files
MySQL中的InnoDB引擎
1.8 - multi level storage
RT thread migration to s5p4418 (I): scheduler
ROS service communication programming
Assembly language learning I (with stack co process, 32-bit registers and related instructions, to be continued 06/29)
SOC project AHB_ SD_ Host controller design
手机开户一般哪个证券公司好?还有,在线开户安全么?
1.5 - logical operation
ROS program compilation, like no compilation, refers to the execution of the old compiled executable program









![[hot100] palindrome substring and longest palindrome substring](/img/a5/10dec640f02023c4d55cb42e6309fb.png)