当前位置:网站首页>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);
});
}
}
边栏推荐
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
- 道阻且长,行则将至
- 概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
- Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
- Matplotlib swordsman - a stylist who can draw without tools and code
- Don't look for it. All the necessary plug-ins for Chrome browser are here
- Knife4j 2. Solution to the problem of file control without selection when uploading x version files
- Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
- Oracle delete tablespace and user
猜你喜欢

概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法

Mysql 多列IN操作

Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed

《统计学习方法》——第五章、决策树模型与学习(上)

Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method

Chrome browser tag management plug-in – onetab

Microservice practice | fuse hytrix initial experience

攻防世界-Web进阶区-unserialize3

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

Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
随机推荐
因上努力,果上随缘
Insight into cloud native | microservices and microservice architecture
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
Knife4j 2.X版本文件上传无选择文件控件问题解决
Talk about the secret of high performance of message queue -- zero copy technology
Mathematics in machine learning -- point estimation (I): basic knowledge
Watermelon book -- Chapter 5 neural network
"Interview high frequency question" is 1.5/5 difficult, and the classic "prefix and + dichotomy" application question
Watermelon book -- Chapter 6 Support vector machine (SVM)
Mysql 多列IN操作
Microservice practice | teach you to develop load balancing components hand in hand
破茧|一文说透什么是真正的云原生
Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
长篇总结(代码有注释)数构(C语言)——第四章、串(上)
Oracle delete tablespace and user
Discussion on improving development quality and reducing test bug rate
C语言之分草莓
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd