What is the Reason For Overriding equals Method in Java ?

The equals() method in Object class is used to check whether two objects are same or not. If we want a custom implementation we can override this method.

For example, a Person class has first name, last name and age. If we want two Person objects to be equal based on name and age, then we can override equals() method to compare the first name, last name and age of Person objects.

Generally in HashMap implementation, if we want to use an object as key, then we override equals() method.



You May Interest

Ruby Tam Sayıdaki Rakamları Ters Sırada Gösterme Örneği

Ruby 1'den N'e Kadar Asal Sayıları Bulma Örneği

Ruby Bugünün Tarihini Getirmek

Ruby Bir Stringdeki Noktalama İşaretlerini Kaldırma Örneği

Ruby Bir Sayının Asal Sayı Olup Olmadığını Bulma Örneği