java - Two ways to check if a list is empty - differences? -
I have a small question.
Let's say we have the list which is called a array list as the list . We want to check whether the list is empty or not.
What is the difference between (if any):
if (list == null) {nothing} and
If (list.isEmpty ()) {something} I am working on an ancient code (somebody else around 2007 Written) and it is using the list == blank build but when we have list.isEmpty () method ...
first let you know whether a list example assigned to list variable Or not.
The second tells you that the list list variable is empty. If list is zero, then the second line will throw a NullPointerException .
If you want to do just that when the list is empty, then it is safe to write:
if (list! = Null & amp; And list.IsITIT ()} {something} If you want to do something if the list is either empty or empty, you can write:
if (list == null || list.isEmpty ()) {something} If you want to do something, then the list is not empty, you can write Are:
if (list! = Null & List.isEmpty ()) {something}
Comments
Post a Comment