This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to check whether string is null or not ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to check whether string is null or not ? " Watch "How to check whether string is null or not ? " New topic
Author

How to check whether string is null or not ?

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 ]

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18


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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: How to check whether string is null or not ?
 
Similar Threads
HashMap iterating problems
A code to print the keys from two different hashMap having same values
null check in Iterator
Iterator<String> problem
Error java util NoSuchElementException