Skip to main content

Memo: null checking for String data

When I write following thing Java compiler out put errer.

======================
String s;

*************

if(s == null)
{
***********
}
=======================
and
======================
String s;

*************

if(s.compareTo(null) == 0)
{
***********
}
======================

But, actuary I have to do following thing.
======================
String s = null;

*************

if(s == null)
{
***********
}
=======================

Comments