if (passengerList!=null&&passengerList.size()>0) {
} else {
}
天蓬老师2017-04-18 10:15:53
List list = new ArrayList();
list is not null, but list.size() is indeed equal to 0
阿神2017-04-18 10:15:53
To give you an example
list==null means you don’t have a cup
size==0 means you have a cup, but there is no water in the cup
If you want to drink water, of course you must have a cup, and there is water in the cup
So double judgment is required
迷茫2017-04-18 10:15:53
Please try to answer the following questions:
If it’s not equal to null, why can’t it be equal to zero?
What is the difference between null and object?
What is the difference between null and empty list?
How did the much-criticized nullpointer exception come about?
巴扎黑2017-04-18 10:15:53
First determine whether the object is empty. This condition is only true if the object is not empty and the size of the list is greater than 0. If your object = null, then when you get the size, it must be a null pointer.
大家讲道理2017-04-18 10:15:53
plist != null Filter this: List plist = null;
plist.size() > 0 Filter this: List plist = new ArrayList();
PHP中文网2017-04-18 10:15:53
list==null means that the object has not been instantiated, list.size()>0 means that the list object cannot contain only one piece of data, and null does not contain size(), it is equal to 0. These are two concepts
大家讲道理2017-04-18 10:15:53
One means that the car has not been built, and the other means that there is a car but no cargo has been loaded
ringa_lee2017-04-18 10:15:53
passengerList.size()>0
This way of writing is actually not good enough. The recommended way of writing is this:
!passengerList.isEmpty()
天蓬老师2017-04-18 10:15:53
public static boolean isEmpty(Collection coll) {
return (coll == null || coll.isEmpty());
}