Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
IF Else Error. Why?
Phillipe Rodrigues
Ranch Hand
Joined: Oct 30, 2007
Posts: 165
posted
May 07, 2008 03:29:00
0
String value1 ="yes"; String value2 =request.getParameter("value2"); .... (1)//Option:<Input type ="text" name ="value2" value ="yes";> Try1 first_try =new Try1(); boolean first =first_try.newValue(value1); .....(2) boolean second =first_try.newValue(value2); .....(3)
Try1.class
public class Try1 { public static boolean newValue(String val){ if(val =="yes") return true; else return false; } }
What should be the output for (2) and (3) and why?
Thanks,
David O'Meara
Rancher
Joined: Mar 06, 2001
Posts: 13459
I like...
posted
May 07, 2008 03:39:00
0
never use '==' evaluation for Strings. Always "value".equals(value)
I agree. Here's the link:
http://aspose.com/file-tools
subject: IF Else Error. Why?
Similar Threads
Constructor Chaining
return value???
Short-Circuit Evaluation
Question mark in Java
Collections problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter