Java,Lambda:如何从具有不同类型的列表集合中查找列表? [英] Java, Lambda: How to find a List from a Collection of Lists with different Types?
本文介绍了Java,Lambda:如何从具有不同类型的列表集合中查找列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是Java 8中从列表列表中获取元素 Type1
的List的最佳方法 - >(记录) {List< ; Type1> ;, List< Type2>,List< Type3>,...}
?
Which is the best way in Java 8 to get a List with elements of Type1
from a List of Lists -> (Records) {List<Type1>, List<Type2>, List<Type3>, ...}
?
记录包含多个具有不同类型的列表 - > {List< Type1>,List< Type2>,List< Type3>,...}
Records has several Lists with different Types -> {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:如何从具有不同类型的列表集合中查找列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文