![]() |
In this article, we want to create a LinkedHashSet of custom objects with specific equality criteria. So, we can create it by overriding the equals and hashcode methods in Java. In the equals() method, we can put the custom criteria over there and we override the hashcode to provide the same Hashcode to our custom object. Example:We want to implement a program that stores the information of students along with its insertion order. However the values must be unique, and the students cannot use the same identities. Approach:
Program to Create a LinkedHashSet of Custom Objects with Specific Equality CriteriaBelow is the code implementation of the creation of a LinkedHashSet of custom objects with specific equality criteria. Java
Output
StudentID: 1, Name: Amit StudentID: 2, Name: Ankit StudentID: 3, Name: Abhishek Explanation of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |