Q:

Foreach not hitting last item

I have a foreach that is suppose to go through and arraylist and perform an action every time an item changes.
So it for something like:
ID | Request
1  |   z
2  |   e

it sends an email to 1 saying "You have 1 request". Then an email to 2 "You have 1 request" and so on.
My loop doesn't address the last item when there's only 2 items in the list and I'm having a difficult time trying to figure out the elegant way to address it.
Integer managerId = null;
Integer previousManagerId = null;
if(requests != null && requests.size() > 0){
        for(Request request : requests){
            managerId = request.getId();

            if((!managerId.equals(previousId) && previousId != null)){
                e.sendEmail(previousId, numReq.toString());
                numReq = 0;
            }
            numReq++;

            previousId = managerId;

        }
        //Suppose to address the last item. Fails when size == 2
        if((!managerId.equals(previousId) && previousId != null)){
            eusendEmail(previousId, numReq.toString());
        }

A:

The last statement of the loop ensures that previousId is always equal to managerId after the loop ends, so it can never go into the if.
I think you always want to send the last email because you know there was at least one request.

