A method call will be executed in each iteration of the loop and is not a free cost. Since you cannot predict how often this happens, calling it once is always less . This is a small optimization, but you should not rely on the compiler to optimize for you.
Next, the outgoingMassages member ..
private ArrayList<OutgoingChatMessage> outgoingMassages ..
... there should be an interface:
private List<OutgoingChatMessage> outgoingMassages ..
Then calling .size() will become a virtual method. To find out a specific class of an object, a method table will be called for all classes in the hierarchy. This again is not exempt from costs.
source share