当前位置:网站首页>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);
});
}
}
边栏推荐
- [go practical basis] how to verify request parameters in gin
- Watermelon book -- Chapter 6 Support vector machine (SVM)
- 长篇总结(代码有注释)数构(C语言)——第四章、串(上)
- C语言之数据插入
- Matplotlib剑客行——没有工具用代码也能画图的造型师
- How to install PHP in CentOS
- 一次聊天勾起的回忆
- How to choose between efficiency and correctness of these three implementation methods of distributed locks?
- 数构(C语言--代码有注释)——第二章、线性表(更新版)
- Solution to amq4036 error in remote connection to IBM MQ
猜你喜欢

盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘

Chrome video download Plug-in – video downloader for Chrome

Creation and jump of activity

Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
![[go practical basis] how can gin get the request parameters of get and post](/img/fd/66074d157d93bcf20a5d3b37da9b3e.png)
[go practical basis] how can gin get the request parameters of get and post
![[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

Mysql 多列IN操作

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

I've taken it. MySQL table 500W rows, but someone doesn't partition it?

Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
随机推荐
攻防世界-Web进阶区-unserialize3
Actual combat of microservices | discovery and invocation of original ecosystem implementation services
How to choose between efficiency and correctness of these three implementation methods of distributed locks?
Say goodbye to 996. What are the necessary plug-ins in idea?
C语言之二进制与十进制
道阻且长,行则将至
Ora-12514 problem solving method
Enterprise level SaaS CRM implementation
C语言之判断直角三角形
What are the waiting methods of selenium
A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
What are the differences between TP5 and laravel
[go practical basis] how to verify request parameters in gin
Microservice practice | fuse hytrix initial experience
Break the cocoon | one article explains what is the real cloud primordial
How to install PHP in CentOS
Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
VIM操作命令大全
[go practical basis] how can gin get the request parameters of get and post