Why do you need !isEmpty check here? It only adds noise, for-each loop handles empty collections already.