当前位置:网站首页>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);
});
}
}
边栏推荐
- Hystrix implements request consolidation
- 数构(C语言--代码有注释)——第二章、线性表(更新版)
- 微服务实战|原生态实现服务的发现与调用
- 大学生四六级作文模板(自创版,成功跨过六级)
- 机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
- Microservice practice | declarative service invocation openfeign practice
- C语言之到底是不是太胖了
- Typeerror: X () got multiple values for argument 'y‘
- Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
- [go practical basis] how to bind and use URL parameters in gin
猜你喜欢
洞见云原生|微服务及微服务架构浅析
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
zk配置中心---Config Toolkit配置与使用
Typora安装包分享
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
Supplier selection and prequalification of Oracle project management system
微服务实战|声明式服务调用OpenFeign实践
[go practical basis] how to bind and use URL parameters in gin
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
Chrome video download Plug-in – video downloader for Chrome
随机推荐
Solutions to Chinese garbled code in CMD window
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
Chrome浏览器插件-Fatkun安装和介绍
MySQL multi column in operation
Microservice practice | load balancing component and source code analysis
Demand delineation executive summary
洞见云原生|微服务及微服务架构浅析
Mysql 多列IN操作
Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
Microservice practice | Eureka registration center and cluster construction
MySQL error: unblock with mysqladmin flush hosts
Creation and jump of activity
[go practical basis] how to set the route in gin
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
西瓜书--第五章.神经网络
分享一篇博客(水一篇博客)
Say goodbye to 996. What are the necessary plug-ins in idea?
深入剖析JVM是如何执行Hello World的
互联网API接口幂等设计