← Back to Users
rabbitsushi's activity in the archive.
Yeah, how about:public class IdMain{ public IdMain(){ go(); } private void go() { String strLitName = "Patrick Naughton"; String strObjName = new String("Patrick Naughton"); if(strLitName == "Patrick Naughton"){ System.out.println("== evaluated to true"); } else{ System.out.println("== evaluated to false"); } if(strObjName == "Patrick Naughton"){ System.out.println("== evaluated to true"); } else{ System.out.println("== evaluated to false"); } } public static void main(String[] args) { new IdMain(); }}
Actually, that really depends what suspect has been initialized to.. If suspect has been assigned a String literal (as opposed to a new String object), the == operator works just fine. :)
Yeah, how about:
public class IdMain
{
public IdMain(){
go();
}
private void go()
{
String strLitName = "Patrick Naughton";
String strObjName = new String("Patrick Naughton");
if(strLitName == "Patrick Naughton"){
System.out.println("== evaluated to true");
}
else{
System.out.println("== evaluated to false");
}
if(strObjName == "Patrick Naughton"){
System.out.println("== evaluated to true");
}
else{
System.out.println("== evaluated to false");
}
}
public static void main(String[] args) {
new IdMain();
}
}
Actually, that really depends what suspect has been initialized to.. If suspect has been assigned a String literal (as opposed to a new String object), the == operator works just fine. :)