Custom Object as a Key in HashMap

Java Custom Object In this Java HashMap example I am going to tell you how to use custom object as a key in HashMap. In custom object as a key in HashMap example, I will show you how to work with user defined objects as keys in Map. To use user defined objects as keys in Map you need to…

How To Add Unique Objects In Java HashSet

Introduction Here in this example I am going to show you how to add unique objects in Java HashSet. Set interface in Java maintains uniqueness, so any duplicacy is not allowed in Set interface. The HashSet class maintains uniqueness through HashMap, so HashSet uses internally HashMap to determine unique elements. When you add String type data or any primitive type…

Override equals() and hashCode() Methods in Java

Introduction Here I will discuss how to override equals() and hashCode() methods in Java. In Java language the important contract is whenever you override one of the methods (equals() and hashCode()), then you must override the other method. So it means that when you override method equals() then you must override hashCode() or vice versa.