aspose file tools*
The moose likes Beginning Java and the fly likes Validating empty string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Validating empty string" Watch "Validating empty string" New topic
Author

Validating empty string

Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
i wrote if (email==""){
System.out.println("error")
}
but it does not show this is i leave emai as empty???
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

You should always compare Strings using the equals method. == will not always return true.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

The == operator here tests whether "" and email point are in the same memory location. Even if the variable email did in fact contain an empty string, the == doesn't know that's what you mean. The equals() method in the String class is a test for what's in the String, rather than where the thing is located.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
Comparing Strings was difficult for me as well. I think this is what you are looking for.



[ September 13, 2005: Message edited by: Stephen Boston ]

Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating empty string
 
Similar Threads
EL operator empty
empty value of body-content
I am a new comer,who can u tell me what means "JQ+"
findXXX methods in EJB 2.x
what's "Assertion expressions should not contain side effects." mean?