[6221] in java-interest

home help back first fref pref prev next nref lref last post

Re: How to check for null ....

daemon@ATHENA.MIT.EDU (Heather Swayne)
Mon Mar 25 20:54:49 1996

Date:         Mon, 18 Mar 1996 14:08:42 PST
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Heather Swayne <hswayne@WRC.XEROX.COM>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>

hi Dhaval and welcome to Java  :)

try:
        if (mystring != null)
                System.out.println("sting is not null");
        else System.out.println("String is null!!!");

happy java,
        Heather

Dhaval M Shah wrote:
>
> To: java-interest@java.sun.com
> Cc: owner-java-interest@java.sun.com
>
> Hello Everybody,
>
> I am a student with good 'C' background and trying to learn
> java.
>
> I have created a string that depending upon input either has some characters or
> has "null" in it. [Or rather the string is null]
>
> My problem is how to check for nullity in java. If the string has "null" and
> I use mystring.length() in the hope that it should return 0, java throws
> a runtime exception.
>
> When I say System.out.println(mystring); it prints null.
>
> In 'C', I could have done something like this :
>
> if(mystring)                            /* Just a crude example */
>         printf("\n string is not null);
> else
>         printf("string is null");
>
> Is there any method (or) a specific way to check for strings with null in it.
>
> Thanks
>
> Dhaval
>
> --
> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
>    Dhaval M. Shah
>    dhaval@cs.uow.edu.au                 (Home) : +61 42 258519
>    Dept. of Computer Science
>    University of Wollongong             2/13 Catherine St., Gwynneville,
>    NSW 2522     Australia               NSW 2500     Australia
> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

home help back first fref pref prev next nref lref last post