List<User> userList  = new ArrayList();
Map<String,String> collect = userList.stream().collect(Collectors.groupingBy(
                User::getRealname, Collectors.mapping(User::getUsername, Collectors.joining(","))));

某个字段值为list

List<User> userList  = new ArrayList();
Map<String,List<String>> collect = userList.stream().collect(Collectors.groupingBy(
                User::getRealname, Collectors.mapping(User::getUsername, Collectors.toList())));