java分组同时执行程序_通过使用Java 8流进行分组

我正在使用Java 8 Streams,我有一个类似于以下的类:

public class ShareDao {

private String senderId;

private String receiverId;

public String getSenderId() {

return senderId;

}

public String sharingMode(){

return this.receiverId != null && !this.receiverId.trim().isEmpty() ? "incoming" : "outgoing";

}

}

现在我想做的是,我想:

>过滤出senderId无效的记录(使用Map<>查找)

>将集合按senderId分组,然后再按shareMode对其进行分组.

下面是我的代码:

Map>> p = records.stream()

.filter(shared -> userMap.containsKey(shared.getSenderId()))

.collect(Collectors.groupingBy(ShareDao::getSenderId),Collectors.groupingBy(ShareDao::sharingMode,Function.identity()));

它抛出了错误:

Error:(105,90) java: no suitable method found for groupingBy(Share[…]gMode,java.util.function.Function)

method java.util.stream.Collectors.groupingBy(java.util.function.Function) is not applicable

(cannot infer type-variable(s) T,K

(actual and formal argument lists differ in length))

method java.util.stream.Collectors.groupingBy(java.util.function.Function,java.util.stream.Collector) is not applicable

(no instance(s) of type variable(s) T exist so that java.util.function.Function conforms to java.util.stream.Collector)

method java.util.stream.Collectors.groupingBy(java.util.function.Function,java.util.function.Supplier,java.util.stream.Collector) is not applicable

(cannot infer type-variable(s) T,K,D,A,M

(actual and formal argument lists differ in length))

当Intellij Idea引发错误时

无法从静态上下文引用非静态方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值