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

String validation

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hello all,

In my code I have declared a String name;

An I am doing following validations..
if(name == null)
{doSomething; }
else if(name != null){do Somethign;}

What I have observed is when I write if(name != null)condiiton before if(name == null)condiiton, when the name is not null the if(name != null) condiiton is ignored.
but if works fine as mentioned in the first para.

why is this happening?

thanks,
trupti
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
since a value can be either null or not null there is no need for both conditions:

is how you can validate your strings.

if the conditions are exclusive, then the order is not important.


pascal
Ben Ethridge
Ranch Hand

Joined: Jul 28, 2003
Posts: 108
I agree with Pascal, but just for the sake of argument, I wrote a simple one:



Works ok for me. You sure there isn't something else going on (maybe some subtlety) in your code?

Point of TV trivia: Who (or should I say what) used to shout the String I have in the else above?

Ben
SCJB 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String validation