Collections.singletonMap()用法

Collections.singletonMap()用于返回单集合

具体用法:

        List list = new ArrayList();
        User user1 = User.builder().id("aaaaa").username("test1").build();
        User user2 = User.builder().id("bbbbb").username("test2").build();

        list.add(user1);
        list.add(user2);

        Map> singletonMap = Collections.singletonMap( "list",list);
        System.out.println(singletonMap);

输出结果:

{list=[User(id=aaaaa, username=test1, password=null, phone=null, email=null, status=null, createTime=null, updateTime=null), User(id=bbbbb, username=test2, password=null, phone=null, email=null, status=null, createTime=null, updateTime=null)]}

你可能感兴趣的:(服务端,Collections)