|
Forum sur la provence, l'astrologie et divertissement, forum voyance, webcam, forum télévision sur internet, les web tv, tourisme, cuisine, gastronomie, forum webmaster
|
Voir le sujet précédent :: Voir le sujet suivant |
Auteur |
Message |
ishaD
Inscrit le: 15 Juil 2023 Messages: 8
|
Posté le: Sam Juil 15, 2023 9:22 am Sujet du message: What is the difference between "==" and ".equ |
|
|
The difference between "==" and ".equals()" in Java lies in their functionality and the types of objects they are used with.
The "==" operator is used for reference comparison. It checks if two objects refer to the same memory location, essentially comparing the memory addresses. When applied to primitive data types, it compares their values. However, when used with objects (non-primitive types), it checks if the references of the two objects point to the same memory location, indicating they are the exact same object.
On the other hand, the ".equals()" method is used for content comparison. It compares the actual values or contents of two objects, rather than their memory addresses. The ".equals()" method is generally overridden by classes to provide custom comparison logic based on the object's internal state. By default, the ".equals()" method in Java compares memory addresses, similar to the "==" operator.
It's important to note that the ".equals()" method is not available for all objects in Java. It is typically defined and implemented in classes that need to provide specific comparison logic, such as String, StringBuilder, and user-defined classes.
In summary, "==" is used for reference comparison, checking if two objects are the same instance, while ".equals()" is used for content comparison, determining if two objects have the same values or states based on the implementation provided by the class.
Java training in pune |
|
Revenir en haut |
|
|
|
|
Vous pouvez poster de nouveaux sujets dans ce forum Vous pouvez répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum
|
Menu du site As-tu-vu: As tu vu - Météo - Programme télé - Astrologie - Médium voyance par webcam - Pendule - Horoscope - Annuaire cuisine et ésoterisme - Blog - Blagues - Résolution d'écran - Cours d'anglais - Provence - Cote d'azur - Aix en provence - Camargue - Marseille - Lubéron
Partenaires: Référencement - Did You Mean - Bongag - Ouaj Voyage
|