小编Kar*_*yap的帖子

使用流获取层次结构中所有项目的名称

class ParentItem {
    String itemName;  //I want to get this property for all the objects in hierarchy
    Integer itemCode;
    List<ParentItem> childItem;
}
Run Code Online (Sandbox Code Playgroud)

我想使用流获取所有项目的名称(ParentItem 名称、ChildItem 名称、GrandChildItemName),如何实现?假设 ChildItem 也有一个 Child,这意味着 ParentItem 有一个 GrandChild!所以嵌套有 3 层。如何实现这一目标?

java collections loops java-stream

-3
推荐指数
1
解决办法
641
查看次数

标签 统计

collections ×1

java ×1

java-stream ×1

loops ×1