Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check the return data list is null?

Status
Not open for further replies.

porkymin

Programmer
Dec 26, 2004
16
0
0
SG
Hi all,
I have the following Collection declared as followed. How do i check whether the return collection is null or empty?

say i have: ml = getReport((List)mndDataLst);

I have tried to check whether return data list is null as described but it does not work.

if(ml == null || ml.isEmpty()){

//doesn't execute this block
}

Can anyone kindly advise me?


public static Collection getReport(List dataList) {
if (dataList == null || dataList.isEmpty()) {
return new ArrayList();
}
Collections.sort(dataList, new Comparator() {
public int compare(Object a, Object b) {
if (a != null && b !=null) {

Val[] v1 = ((ReportRow)a).getData();
String c = (String)v1[3].getData();

Val[] v2 = ((ReportRow)b).getData();
String d = (String) v2[3].getData();

return (c.compareTo(d));
}
else if (a== null && b !=null) {
return -1;
}
else
return 1;
}
});
return dataList;
}
 
Well, maybe the Collection is not empty ...

Did you try printing out the size of the collection?

Cheers,
Dian
 
how to print out the size of the collection?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top