How can I check if List <obj> is null?
I have a list that takes a list from my server. this list will contain whatever the server finds in the ex database.
List<OBJ> lstObj = new Arraylist<OBJ>;
Service.getOBJ(new AsyncCallback<List<OBJ>>(){
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
@Override
public void onSuccess(List<OBJ> result) {
//line to check if result is null
}
});
I tried
if(result==null){
}
and also tried
if(result.isempty(){
}
but it didn't work. the list will be empty if the server does not find any records from the database. all i have to do is check if empty is empty.
source to share
Checking that the list is empty and checking whether it is result
zero are two different things.
if (result == null)
will see if the value is a result
null reference, that is, it does not belong to any list.
if (result.isEmpty())
will see if the value is a result
reference to an empty list ... the list exists, it just doesn't have any elements.
And of course, in cases where you don't know if it can result
be empty or empty, just use:
if (result == null || result.isEmpty())
source to share
You are obviously new to this programming task if you haven't checked your server yet, so I'm trying to figure out what might happen to your server. Depending on your "objects", you may have valid objects, which are data that are meaningless in different ways. For example, you can have String objects with different types of spaces.
This happens on servers that provide responses using PHP and JSP, where pages are assembled using various include mechanisms and there is a gap between them.
source to share