I know this is simple but I couldn't find any question on it.
When I check if a list is null and then iterate over it, how it affects on performance?
I have the following code and I wonder if the second call to getContainers() perform the method again or the compiler is saving the list so it don't have to run getContainers() again.
if (getContainers() != null)
{
for (Container container : getContainers())
{...
if this is not true I was thinking of doing something like this code below but it seems to naive.
List<Container> listC = getContainers();
if (listC != null)
{
for (Container container : listC)
{...