当前位置:网站首页>Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
2022-07-02 09:33:00 【Janson666】
How to get map Middle all key value , All value value , And get all at the same time key and value value ?
1. obtain map All key values in (keySet Method ), The output adopts lambda expression
Map<String, Object> attrMap = Files.readAttributes(path, "*", LinkOption.NOFOLLOW_LINKS);
// obtain map All key values in
Set<String> keySet = attrMap.keySet();
keySet.forEach(key -> System.out.println(key));
2. obtain map All of value value ,(values Method ), The output adopts foreach
Collection<Object> values = attrMap.values();
for (Object value: values) {
System.out.println("map Medium value The value is :" + value);
}
3. Simultaneous acquisition key value and value value (entrySet Method ). Output adopts two methods ,iterator iterator perhaps foreach loop ,lambda Expression form
// Can be obtained at the same time map Medium key value and value value
Set<Map.Entry<String, Object>> entrySet = attrMap.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> next = iterator.next();
String key = next.getKey();
Object value = next.getValue();
System.out.println("key The value is "+ key+ " value The value is :" + value);
}
System.out.println("============ use foreach loop , Get key value and value value ============");
entrySet.forEach(entry -> {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("key The value is "+ key+ " value The value is :" + value);
});
All the codes in this test :
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
/** * @Author Janson * @Date 2022/4/20 9:17 * @Version 1.0 */
public class Day4_Files {
public static void main(String[] args) throws Exception {
Path path = Paths.get("O:\\code\\BeforeSleeping30m\\testData");
// Get the properties of the file
//{@code "*"} then all attributes are read.
// LinkOption.NOFOLLOW_LINKS Don't follow the symbolic connection
Map<String, Object> attrMap = Files.readAttributes(path, "*", LinkOption.NOFOLLOW_LINKS);
// obtain map All key values in
Set<String> keySet = attrMap.keySet();
keySet.forEach(key -> System.out.println(key));
// obtain map All of value value
Collection<Object> values = attrMap.values();
for (Object value: values) {
System.out.println("map Medium value The value is :" + value);
}
// Can be obtained at the same time map Medium key value and value value
Set<Map.Entry<String, Object>> entrySet = attrMap.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> next = iterator.next();
String key = next.getKey();
Object value = next.getValue();
System.out.println("key The value is "+ key+ " value The value is :" + value);
}
System.out.println("============ use foreach loop , Get key value and value value ============");
entrySet.forEach(entry -> {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("key The value is "+ key+ " value The value is :" + value);
});
}
}
边栏推荐
- In depth analysis of how the JVM executes Hello World
- Creation and jump of activity
- Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
- Troubleshooting and handling of an online problem caused by redis zadd
- Typora安装包分享
- Solutions to Chinese garbled code in CMD window
- 互联网API接口幂等设计
- A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
- JVM instruction mnemonic
- Microservice practice | teach you to develop load balancing components hand in hand
猜你喜欢

BugkuCTF-web24(解题思路及步骤)
![[go practical basis] how to bind and use URL parameters in gin](/img/63/84717b0da3a55d7fda9d57c8da2463.png)
[go practical basis] how to bind and use URL parameters in gin

Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc

Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程

How to use PHP spoole to implement millisecond scheduled tasks

企业级SaaS CRM实现

Enterprise level SaaS CRM implementation

web安全与防御

知识点很细(代码有注释)数构(C语言)——第三章、栈和队列

hystrix 实现请求合并
随机推荐
每天睡觉前30分钟阅读_day4_Files
Thinkphp5 how to determine whether a table exists
Say goodbye to 996. What are the necessary plug-ins in idea?
Redis installation and deployment (windows/linux)
[go practical basis] how to verify request parameters in gin
定时线程池实现请求合并
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
VIM operation command Encyclopedia
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
Talk about the secret of high performance of message queue -- zero copy technology
[go practical basis] how to set the route in gin
Discussion on improving development quality and reducing test bug rate
Mysql默认事务隔离级别及行锁
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
数构(C语言)——第四章、矩阵的压缩存储(下)
zk配置中心---Config Toolkit配置与使用
How to use pyqt5 to make a sensitive word detection tool
[go practical basis] how can gin get the request parameters of get and post
洞见云原生|微服务及微服务架构浅析