List<String> listStr = new ArrayList<String>();
if(listStr.size == 0){
}
versus
if(listStr.isEmpty()){
}
In my view one of the benefits of using listStr.isEmpty()
is that it doesn't check the size of the list and then compares it to zero, it just checks if the list is empty. Are there any other advantages as I often see if(listStr.size == 0)
instead of if(listStr.isEmpty())
in codebases? Is there is a reason it's checked this way that I am not aware of?