ayush raj wrote:How many objects are created if i write the following codes
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
ayush raj wrote:How many objects are created if i write the following codes in java 1.6 :
String str1="abc";// case 1
String str2=new String("abc");//case 2
Does str1 will also be stored in the some string literal pool or only str2 would be stored in the pool ?
ayush raj wrote:But then how could i know if two objects have been created or only one object is created ?
ayush raj wrote:@C Halbe : And what about equals method? How does it manipulate the strings equality? For the case 1 : does any object exist on the heap ?
ayush raj wrote:Totally confused relating to String constant pool and the heap .
public class StringTest {
public static void main(String[] args) {
String str1 = "abc";
String str2 = new String("abc");
System.out.println(" str1 == str2"+ str1 == str2);
}
}
Helen Ma :the print statement is interpreted in this way : the first string is "str1 == str2 "+ str1 which is "str1 == str2 123". The second string is str2 which is 123.
str1 == str2 123 is not equal to 123 . So, the answer is false.
Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Always look on the bright side of life. At least this ad is really tiny:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|