Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PLZ tell me ,what's wrong in it????

 
Sura Lin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String ss=request.getParameter("select");
if(ss=="*"){ss="all";}
can you tell me why (ss="all") is not execute when ss's value is "*"

thanks
 
gautam shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sura Lin:
String ss=request.getParameter("select");
if(ss=="*"){ss="all";}
can you tell me why (ss="all") is not execute when ss's value is "*"

thanks

try
if(ss.equals("*"))
{ss="all";}
object references of String literals can't be compared in this way to get desired results. this kind of comparision is also possible but that is a another story..

ooops i forgot that i have to finished my PPL book as soon as possible to clear my concepts regarding variable and objects. let me Run...
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String ss = ( String) request.getParameter("select");
if( ss == null ) ss = "";
// now you can evaluate ss
if( ss.equals("*") ) ss = "all";
// if ss contained "*" then it should now
// be "all"
 
Sura Lin
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.Your reply is very useful.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
String ss = ( String) request.getParameter("select");

This cast is unnecessary since getParameter() always returns a String.
-anthony
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic