Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null comparison

 
Tyler Jordan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a value in an array that has certain values that are null when I do a println command on them. I need to do an statement that compares these value to null. (either that it equals or doesn't equal null). I have tried the equals method and the operators, but neither compares the values correctly. Is this a special case in Java? How should I compare these?
 
Chris Harris
Ranch Hand
Posts: 231
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tyler,
Compare null values are null do the following instead of using the equals method:
if (ipArray[s] == null) //is null
if(ipArray[s] != null) // if not null.

You can't do:
ipArray[s].equals(null)
as there is no instance created for the value so there will not be a pointer to the object. If you do this you will get a NullPointerException if ipArray[s] is null.
Hope that helps. Let us know if you have any more problems.
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic