Considering the code below:
- How is the
str1object created without usingnew String()? - Why do the
str1andstr2objects refer to same memory location?
String str1 = "hello";
String str2 = "hello";
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is all described in the java language specification.
See 3.10.5 String Literals: