我是Java 8 Streams的新手,并希望将以下代码块转换为Java 8的Stream方式来做同样的事情.
编辑:更新类名称以减少混淆.(删除了Foo,Bar,Baz ...)
ArrayList<PriceList> priceLists = new ArrayList<PriceList>();
// I'm casting to a type-safe List from getObjects()
// -which is a function I dont have access to. Is there a nice
// solution to embed this in the stream-syntax?
List<PriceListGroup> distObjects = (List<PriceListGroup>) objects.get(1).getObjects();
for(PriceListGroup group : distObjects) {
Set<Affiliate> affiliates = group.getAffiliates();
for(Affiliate affiliate : affiliates) {
priceLists.add(affiliate.getPriceList());
}
}
Run Code Online (Sandbox Code Playgroud)
所有帮助和解释表示赞赏