• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How To Compare Null

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to compare string with null values.so how can i do it using strings???
thanx in advance.
regards,
Samir
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know that one of the two strings will not be null (usually because it is a constant) then use that to compare with the other. A null string will not be equal to a non-null string. For example:
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,
Sorry i couldnt get ur answer can u please explain me in details
Comparing string with null values???
Kajol
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any object reference can be compared to null and a String is an object.

Hope this helps
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol/Carl,
Frank's suggestion will also work and is more elegant and easier to read. The implementation of String.equals() checks to see if the input paramater is null. If it is, then it will return false.
Since null is checked inside the implementation, then Carl's method can be simplified to:

-Peter
 
Samir Narale
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx carl,Frank
i got the inn thing.
regrds
sam
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!