当前位置:网站首页>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);
});
}
}
边栏推荐
- 大学生四六级作文模板(自创版,成功跨过六级)
- Knife4j 2.X版本文件上传无选择文件控件问题解决
- Safety production early warning system software - Download safety production app software
- 微服务实战|熔断器Hystrix初体验
- 深入剖析JVM是如何执行Hello World的
- Redis installation and deployment (windows/linux)
- Alibaba /热门json解析开源项目 fastjson2
- Microservice practice | load balancing component and source code analysis
- Programmers with ten years of development experience tell you, what core competitiveness do you lack?
- Mysql 多列IN操作
猜你喜欢

How to use PHP spoole to implement millisecond scheduled tasks

Solutions to Chinese garbled code in CMD window

一篇详解带你再次重现《统计学习方法》——第二章、感知机模型

Matplotlib剑客行——初相识Matplotlib

Talk about the secret of high performance of message queue -- zero copy technology

Supplier selection and prequalification of Oracle project management system

Insight into cloud native | microservices and microservice architecture

Chrome浏览器标签管理插件–OneTab

MySQL multi column in operation

Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
随机推荐
[go practical basis] gin efficient artifact, how to bind parameters to structures
Microservice practice | fuse hytrix initial experience
Typora安装包分享
记录一下初次使用Xray的有趣过程
Enterprise level SaaS CRM implementation
How to use pyqt5 to make a sensitive word detection tool
JDBC回顾
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
Supplier selection and prequalification of Oracle project management system
Amq6126 problem solving ideas
因上努力,果上随缘
破茧|一文说透什么是真正的云原生
Say goodbye to 996. What are the necessary plug-ins in idea?
Fragmenttabhost implements the interface of housing loan calculator
Learn combinelatest through a practical example
Oracle delete tablespace and user
Micro service practice | introduction and practice of zuul, a micro service gateway
Microservice practice | Eureka registration center and cluster construction
大学生四六级作文模板(自创版,成功跨过六级)
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"