One addition to Mark's code. You could check for these two conditions in one IF statement to use Java's feature to "conditionally check conditions".
 
if ((null != s) && (s.length() != 0))
{
}
 
If 's' equals null, the second condition will not be checked.
 
Ganesh
 
----- Original Message -----
From: "John McDonald" <[EMAIL PROTECTED]>
To: "A mailing list for discussion about Sun Microsystem's Java Servlet API Technology." <[EMAIL PROTECTED]>
Sent: Wednesday, January 05, 2000 07:56 PM
Subject: Re: Re: Checking for null

> s is null unitl a user enters some data, so there wil be a possiblity that
> the variable will be null. This is my problem
>
> John D. McDonald
> CipherStream Systems
> Phone: 925.373.8700
> Fax:     413.793.6603
> email:
[EMAIL PROTECTED]
> web: www.cipherstream.com
> -------------------------------------------------------
> Secure E-Business Is Our Business
> -------------------------------------------------------
> ----- Original Message -----
> From: Mark Foley <
[EMAIL PROTECTED]>
> To: <
[EMAIL PROTECTED]>
> Sent: Wednesday, January 05, 2000 4:22 PM
> Subject: Re: Checking for null
>
>
> > Hi,
> >
> > Wouldn't your conditional statement cause a null pointer exception if s is
> > null? Try it!
> >
> > I do this:
> > ...
> > if(null != s) {
> >     if(s.length() != 0) {
> >         // it's not null and it's not empty
> >     }
> > }
> >
> > Regards,
> > Mark
> >
> > > -----Original Message-----
> > > From: Richard Clark [
SMTP:[EMAIL PROTECTED]]
> > > Sent: Thursday, 6 January 2000 10:34
> > > To:  
[EMAIL PROTECTED]
> > > Subject:      Re: Checking for null
> > >
> > > To check for both null and zero length:
> > >
> > > String s = req.getParameter("value");
> > > if (null == s || s.length() == 0) {
> > >   // it's null or empty
> > > }
> > >
> > > For just null, use (null == s)
> > >
> > > ...Richard
> > >
> > > -----Original Message-----
> > > From: John McDonald [
mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, January 05, 2000 3:03 PM
> > > To:
[EMAIL PROTECTED]
> > > Subject: [SERVLET-INTEREST] Checking for null
> > >
> > >
> > > I am retrieving a value from a web page with req.getParameter("value").
> > > How
> > > do I check if the string is null without getting a null pointer
> exception.
> > > Any ideas would be helpful.
> > >
> > >

Reply via email to