what is the difference between equals method and ==

Answer Posted / subrahmanyam

== is userd to compare both are of same type
equals is used to compare both are of same contents


EX:
String s1="raju";
String s2=new String("raju");
if(s1.equals(s2))
System.out.println(" if(s1.equals(s2)"); //true
if(s1==s2)
System.out.println(" s1==s2"); //false

Is This Answer Correct ?    62 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what access modifiers can be used for variables?

593


Difference between comparator and comparable in java?

623


What is an error in java?

642


What is the difference between serial and throughput garbage collector?

588


What is super?

589






Why inputstreamreader is used in java?

554


Does substring create a new object?

530


What are the four integer types supported by java?

566


What does java ide mean?

645


Which api is provided by java for operations on set of objects?

917


how to open and edit XML file in Weblogic???

1554


How does the java compiler work?

532


Does java support multiple inheritance or not?

605


What the difference is between execute, execute Query, execute Update?

378


Which class represents the socket that both the client and server use to communicate with each other?

578