Java, lambda : How to find a List from a Collection of Lists with different Types?

标签 java lambda filter prediction

这是 Java 8 中获取包含 Type1 元素的列表的最佳方法。来自列表列表 ->(记录){List<Type1>, List<Type2>, List<Type3>, ...}

记录有多个不同类型的列表 -> {List<Type1>, List<Type2>, List<Type3>, ...}

List<T> getList(T t) {
  // t is instance of Type1
  return Records -> List<t>;
}

非常感谢您的帮助。

最佳答案

class Utils<T> {

    List<T> getList(T t, List<List> list) {
        return list.stream().filter(i -> t.getClass().isInstance(i.get(0))).flatMap(List<T>::stream).collect(Collectors.toList());
    }
}

关于Java, lambda : How to find a List from a Collection of Lists with different Types?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46894007/

相关文章:

c++ - gcc 无法使用此捕获编译通用 lambda

具有多个排除的 Elasticsearch 聚合查询

java - 基于 MATLAB 的 Java 程序

java - 如何使用 xuggler 库制作可执行文件 java

Java - 将用户输入放入数组中

java - 为什么当我在静态 block 中不使用 "lambda method reference"代码风格时会导致死锁?

node.js - 使用 AWS Lambda 获取 url feed 的代理

python - 使用字典中的键从数据帧中检索值

javascript - 检查对象是否具有基于数组的多个值

linux - 找到 native 库时出现 Java UnsatisfiedLinkError