File size: 707 Bytes
0284885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package Stream_initial_package;

import java.util.HashMap;

public class Stream_demo3 {
    public static void main(String[] args) {
        //双列集合      无法直接使用Stream流

        //1、创建双列集合
        HashMap<String, Integer> hm = new HashMap<>();
        //2、添加数据
        hm.put("aaa", 111);
        hm.put("bbb", 222);
        hm.put("ccc", 333);
        hm.put("ddd", 444);

        //3、第一种获取stream流
        hm.keySet().stream().forEach(s -> System.out.print(s + " "));
        System.out.println();

        //4、第二种获取stream流
        hm.entrySet().stream().forEach(s -> System.out.print(s + " "));
        System.out.println();
    }
}