Say I have a custom datatype:
public class Notification {
private String name;
private String location;
private String message;
// Constructors, getter, setters, etc.
}
And I want to add objects (of Notification
type) from a list to a Set to get rid of duplicates. But just simply adding them to a Set doesn't work because Java doesn't know how to check to see if there are duplicates.
How do I tell Java that when I add a Notification
object to a set, I want it to only check whether the name
attribute is unique or not (disregarding other fields)?