蝙
蝙蝠
Unregistered / Unconfirmed
GUEST, unregistred user!
This is a question about String compare.The result is different if generate string with different way--one is using keyword "new",another isn't.Please help me answer:Why did this happen?What difference between these two way?Wheredo
es the string object store?Stack or heap?on the other hand,please correct my language error.
This is my program:
public class CompareString
{public static void main(String[] args)
{String string1=new String("good");
String string2=new String("good");//first way,generate string with "new",answer is "false".
//String string1="good";
//String string2="good";//second way,generate string without "new",answer is "true".
System.out.println("string1 equal string2 is:"+(string1==string2));
}
}
es the string object store?Stack or heap?on the other hand,please correct my language error.
This is my program:
public class CompareString
{public static void main(String[] args)
{String string1=new String("good");
String string2=new String("good");//first way,generate string with "new",answer is "false".
//String string1="good";
//String string2="good";//second way,generate string without "new",answer is "true".
System.out.println("string1 equal string2 is:"+(string1==string2));
}
}