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?

0

1 Answer 1

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..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.