这是 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/