当前位置:网站首页>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);
});
}
}
边栏推荐
- Chrome视频下载插件–Video Downloader for Chrome
- Matplotlib剑客行——布局指南与多图实现(更新)
- [go practical basis] how to bind and use URL parameters in gin
- 微服务实战|Eureka注册中心及集群搭建
- Fragmenttabhost implements the interface of housing loan calculator
- hystrix 实现请求合并
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 双非本科生进大厂,而我还在底层默默地爬树(上)
- 每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
- 每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
猜你喜欢
企业级SaaS CRM实现
Matplotlib剑客行——初相识Matplotlib
[go practical basis] how to bind and use URL parameters in gin
Enterprise level SaaS CRM implementation
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
个人经历&&博客现状
MySQL multi column in operation
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
BugkuCTF-web24(解题思路及步骤)
随机推荐
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
Required request body is missing:(跨域问题)
因上努力,果上随缘
Safety production early warning system software - Download safety production app software
微服务实战|原生态实现服务的发现与调用
互联网API接口幂等设计
Alibaba /热门json解析开源项目 fastjson2
上班第一天的报错(Nessus安装winpcap报错)
Learn combinelatest through a practical example
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Machine learning practice: is Mermaid a love movie or an action movie? KNN announces the answer
一次聊天勾起的回忆
Chrome浏览器插件-Fatkun安装和介绍
[go practical basis] how can gin get the request parameters of get and post
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
hystrix 实现请求合并
Flink - use the streaming batch API to count the number of words
自定義Redis連接池
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method