Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if an object is null

Tags:

java

I have a linked list in which first node contains null object. means firstNode.data is equal to null, firstNode.nextPointer = null, firstNode.previousPointer = null.

And I want to check if firstNode is null or not. So I tried-

if(list.firstNode == null){

            //do stuff          
        }

but this doesn't works?

I also tried equals too. Any suggestions?

I tried printing. And I got as-

{null} -- firstNode

like image 308
AKIWEB Avatar asked Feb 19 '12 19:02

AKIWEB


2 Answers

I think your firstNode is not null, but its fields are. Try something like this:

if (list.firstNode.data == null) {
    //do stuff          
}
like image 120
Bohemian Avatar answered Oct 13 '22 00:10

Bohemian


Did you try

if (list.firstNode.data == null) { /* Do stuff */ }
like image 33
Skip Head Avatar answered Oct 13 '22 00:10

Skip Head