java - way to find the List of all ids in a list of entities from inner object with java 8
问题描述
I have an entity:
public class Entity
{
private long id;
private InnerEnity data;
public long getId() {
return id;
}
public InnerEnity getData() {
return data;
}
}
InnerEnity class
public class InnerEnity
{
private long id;
private String data;
public long getId() {
return id;
}
public String getData() {
return data;
}
}
what i need is list of InnerEnity ids. TO resolve this i tried something like that :-
List innerEnityIds = listOfEnity.stream().map(sys -> sys.getData().stream().map(obj->obj.getId().collect(Collectors.toList())));
解决方案
You just need to map
the entity
to its inner entity's(data
) id
as :
List<Long> innerEnityIds = listOfEnity.stream()
.map(entity -> entity.getData().getId()) // <<< this
.collect(Collectors.toList());
推荐阅读
- android - 如何在android数据绑定中的三元运算符中提及属性(?attr)?
- java - 春季批处理应用程序中堆积的 Atomikos 线程
- sonarqube - 带有 java 项目的声纳扫描仪
- php - PHPUNIT如何测试一个值在一种情况下不存在?
- python - 将 Yahoo 数据转换为 pandas 数据框
- java - 蟒蛇pyjnius; PythonActivity错误我安装了JDK+Visual C++
- mysql - 列相关条件的总和
- reactjs - 使用 ReactJS 如何在 Firestore 中订阅多个 onSnapshot 集合更改
- ffmpeg - 有没有办法在将 mjpeg 流编码为 h264 时强制 ffmpeg 生成 I 帧
- java - 如何从另一种方法返回值或字符串