SCJP 1.4, SCBCD 1.3
1 String s1 = "Amit";
2 String s2 = "Amit";
3 String s3 = new String("abcd");
4 String s4 = new String("abcd");
5 System.out.println(s1.equals(s2));
6 System.out.println((s1==s2));
7 System.out.println(s3.equals(s4));
8 System.out.println((s3==s4));
Hi,
Soni Firstly
== Checks the Object reference equality,while
equals Checks the Object value equality,Secondly
When you code:
String S="JavaRanch";
String S1="JavaRanch";
these are just reference variables not Object
until we don't use new operator and when we
use new it refers to two different new objects
while if we are not using new then it refers to
String Pool.
"Do not be afraid of going slow, be afraid of standing still"
SCJP 1.4, SCBCD 1.3
SCJP 1.4, SCBCD 1.3
R Pinjarkar wrote:how much objects will be created from
1) String s=”amit” 2) String s=”amit” 3) String s=new string ”amit"
What is the answer
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Hey cool! They got a blimp! But I have a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|