India Jobs- IT Fresher Job in Delhi, Bangalore, Mumbai, Chennai.
www.Lkshya.com
Ask Your Query

Q. What is difference between == and equals() while comparing strings? Which one is reliable?




Characters Left
3 + 8
Bharat Gusain
Both equals() method and == operator is used to compare two objects in Java. == is an operator and equals() is method. But == operator compare reference or memory location of objects in the heap, whether they point to the same location or not .
Saurav kumar
Equal is more reliable to the strings.It is also compare the value of variables
Smile
== operater is used for referenced variable wise comparison if both are equal send created is duplication. If is false search datawisecomparision using equals().
Indu
How to post free Internship ads?
Joy Basak
1.== is a operator.equals() is a function . 2.== only checks the primitive value but equals() checks the primitive value as well as the memory location for the variable (String). 3.== is not suitable for string comparison but we can do the same work by using equals(). 4. == is used for comparing the reference object and equals() used for comparing the heap object.
Suprakash Pal
i think equals() operator is more reliable as == operator compares the memory address of the variables whereas equals compares the value of the variables.
omprasad
== it is reliable because it compares the two strings
Gourab Ray
Both == operator and equals() for comparing objects in java. But == operator we are using for comaring object reference in the heap. But equals() is to compare the contain of the object in heap. ex- String s1=new String("grv"); String s1=new String("grv"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); output-false true
shweta mahton
Main difference between == and equals in Java is that "==" is used to compare primitives while equals() method is recommended to check equality of objects. equals() is more reliable to compare the strings .
shweta mahton
== is a relational operator.It is used for compare two values. While,equals() is used to check the two strings ,if its equal it return true ,but if it is unequal it return false . In other words it check the equality of two objects.
Top Answered Questions Good at tech answer these

Some other Good Questions

Q:1 What is a Constructor in Java?

Q:2 How are positive(+ve) and negative(-ve) numbers represented internally in Java?

Q:3 What do Trojans, Viruses, and Other Malware do to our systems?

Q:4 Can abstract class have constructor in java?

Q:5 Difference between checked vs unchecked exception in Java?

Q:6 When is checked exception in Java?

Q:7 What is difference between == and equals() while comparing strings? Which one is reliable?

Q:10 Can we call a class a data type?

Q:11 What is the difference between #include and import statement?

Q:12 What is JIT Compiler?

Q:13 What is a swap space in Linux?

Q:14 What is the basic difference between BASH and DOS?

Q:15 How do you refer to the parallel port where devices such as printers are connected?

Q:16 How do you switch from one desktop environment to another, such as switching from KDE to Gnome?

Q:17 How does case sensitivity affect the way you use commands?

Q:18 Is it possible to use shortcut for a long pathname?

Q:19 How do you terminate an ongoing process?

Q:20 Write a command that will display all .txt files, including its individual permission in Linux.

India Jobs-How to get fresher software jobs in India| Search Jobs