File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String validation

 
trupti nigam
Ranch Hand
Posts: 623
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic