0

I have following use case

 class Agree{

 }

 class Agreebody{
    Agree agree;
 }

 class AgreeFull{
   List<AgreeBody> agreebody;
 }

The requirement is to create a List of all Agrees present inside AgreeBody List.

 List<Agree> l = new List<Agree>
 agreeFull.getAgreeBody.stream(). ? //Need to get Agree from Each agreebody and make list of agrees

Shall i call .forEach and do it manually or other better way?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
fatherazrael
  • 5,511
  • 16
  • 71
  • 155

1 Answers1

3

You can use map

List<Agree> l = agreeFull.getAgreebody().stream()
        .map(AgreeBody::getAgree)
        .collect(Collectors.toList());

You need also to focus on some part of your code, for example using getter and setters, significant name for the attributes and class..

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140