differences between == and .equals()
What are the differences between == and .equals() in java ?
|
Quote:
== compares references while .equals compares contents. The method public boolean equals(Object obj) is provided by the Object class and can be overridden. The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator == being used to compare aliases to the object. String, BitSet, Date, and File override the equals() method. For two String objects, value equality means that they contain the same character sequence. For the Wrapper classes, value equality means that the primitive values are equal. |
Code:
public class EqualsTest { |
Quote:
Output == comparison : true == comparison : true Using equals method : true false Using equals method : true |
All times are GMT +5. The time now is 12:17 PM. |
Powered by: vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
MyHindiForum.com is not responsible for the views and opinion of the posters. The posters and only posters shall be liable for any copyright infringement.