How Java 8 lamada Stream: gets a collection of child attributes of an attribute

is like this. There is an order list List < order > whose order contains several goods. Now you want to get the id,model structure of all goods in the order list as follows:

class order {
int id,
List < goods > goodsList;
}
class goods {
int id;
String name;
}

List < order > list.
you can get the id list of the order. The question now is how to get the list of items under all the list orders,
list.stream (). Map (c-> c.getId ()). Orders (Collectors.toList ()) < order >.
the following words do not seem to be correct
list.stream (). Map (c-> c.getGoodsList (). Stream (). Map (Q-> q.getId (). Collect (Collectors.toList ());

Mar.14,2021

give it a try

list.stream()
    .map(order::getGoodsList)
    .flatmap(goods::getId)
    .map(x -> new Integer(x))
    .collect(Collectors.toList())

, note that List cannot be int and must be Integer


nested loops would be fine

orders.stream.map(order->{
      return
      order.getGoodList().map(good->{
               return good.getId();
       }).collect(Collectors.toList());
}).collect (Collectors.toList());
Menu