Map之“获取map中的key流转为List”

一.获取map中的key转为List

注意

这里可以获取map中所有的key来转换为List, 这样后很多方案就不需要另外查询出来处理了

代码

    @Test
    public void test()
    {
        Map<Integer, Double> ratioMap = new HashMap<>();
        ratioMap.put(1, 1.2);
        ratioMap.put(1, 1.3);
        ratioMap.put(2, 2.1);

        List<Integer> keys = ratioMap.keySet().stream().collect(Collectors.toList());

// keys = [1, 2] System.out.println(
"keys = " + keys); }

结果图

 

posted @ 2022-10-29 09:26  骚哥  阅读(3611)  评论(0编辑  收藏  举报