[6266] 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 (Lee Collins)
Wed Mar 27 01:34:44 1996

Date:         Tue, 19 Mar 1996 13:57:00 -0600
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Lee Collins <spacely@XSITE.NET>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>

In Java, it goes like this:

String s;

s  = "Hello World";
// NOW there is something in the string
if (s == null)
        System.out.println("\n string is null");
else
         System.out.println("\n string is not null"); // this one

s  = null;
// NOW its NOT
if (s == null)
        System.out.println("\n string is null"); // this one
else
         System.out.println("\n string is not null");

At 07:17 PM 3/18/96 +1100, 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).

-----
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