Why a same program output a different result?
class aa
{
static void cg(String c,int d)
{ String s1=c;
Integer i=new Integer(d);
String s2;
s2=i.toString();
if(s1==s2)System.out.println(true);
else System.out.println(false);
}
}
class A
{ public static void main(String [ ] args)
{aa.cg("1",1);
aa.cg("11",11);
}
}
//the result is "true" and "false" Why?
[443 byte] By [
JavaEager] at [2007-9-30 13:36:06]

When you use == in a comparison, you're comparing object id's; to compare the content of the String object, use s1.equals(s2)
It is not relevant that your code says the first test matches and the second fails - your code doesn't control the response when you use ==
See this tip http://java.sun.com/developer/TechTips/1999/tt0114.html