This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check whether string is null or not ?

 
Sagar Rohankar
Ranch Hand
Posts: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,

i am chcking a string for null , here is my code



What ll be possible cause, Is iterator making some problem, here ?

Thanks.

Regardz,
[ March 19, 2008: Message edited by: Sagar Rohankar ]
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You know, it hardly ever occurs that toString() returns null for an object; the objectitself is much more likely to be null. Therefore, you should check it.next() instead.

However, it.next() doesn't just return an object, it also goes ahead one step. To prevent this, you should cache the object:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic