0

My application has a methodA that is executed for a service request. Now we would like to send a list of requests instead of single request and for every request methodA has to be called or processed. I could put a basic loop and call the method like

public String findN(criteria criteriaList)  {
    .....................
    for( int i = 0; i < reqList.length; i++ )
    {
        Req req = reqList[i];
        methodA(req);
    }
}

Is there a better programming approach then just looping? Is there a design pattern that covers this aspect?

1
  • There is in Javascript, Scala, etc. Commented Apr 17, 2013 at 14:52

1 Answer 1

3
for(Request req : reqList) {
    MethodA(req);
}

Is the best Java offers currently. More functional languages do this in one line, using methods like .map, .foreach, etc.

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

2 Comments

Java 8 will finally have some of that
Thank you for your responses. I was looking if there was a spring feature or any design pattern wherein without any loops it would just trigger calling the method for every item in the list.

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.