
Posted In: Java Core, Set
How to remove duplicate objects while adding to Collection and Sort – Example2
Use case – We have list of objects (in this case users). We want to remove duplicate users depending on some criteria. Then sort them. In this example with first name. Both of this can be achieved by overriding equals and Comparable.compareTo methods. Result [User [age=35, firstName=Bat, lastName=Man], User [age=35, firstName=Robin, lastName=Hood], User [age=30, firstName=Super, […]
Read MoreTags: Comparable-interface-in-collection-framework, equals, hashCode, HashSet, How do I remove repeated elements from ArrayList?, Java object sorting example Comparable

Posted In: Java Core, Set
How to remove duplicate objects while adding to Collection – Example1
You have list of objects (in this case users). You want to remove duplicate users depending on some criteria. You could iterate through the list ,check some condition and remove duplicates or you could use little simpler approach using HashSet and overridden equals method as below. Result [User [age=30, firstName=Super, lastName=Man], User [age=35, firstName=Bat, lastName=Man], […]
Read MoreTags: equals, hashCode, HashSet, How do I remove repeated elements from ArrayList?, Set
- Apache (13)
- Build Tools (2)
- Gradle (2)
- Caching (1)
- cpanel (1)
- cURL (1)
- Database (7)
- Hibernate (5)
- Java Core (38)
- Java Script (15)
- Bootstrap (1)
- File Upload (7)
- jQuery (3)
- React (3)
- JEE (13)
- JSON (41)
- GSON (13)
- Jackson 1X (1)
- Jackson 2X (12)
- jsoniter (1)
- Logging (2)
- Apache Commons Logging (1)
- Apache Log4J (1)
- Logback (1)
- SLF4J (1)
- MongoDB (1)
- OS (1)
- Linux (1)
- Security (5)
- Server (4)
- Tomcat (4)
- Service (2)
- Micro (2)
- Spring (46)
- Pattern (2)
- Spring Boot (20)
- Spring Data (4)
- Spring MVC (8)
- Spring REST (13)
- Spring Security (7)
- Testing (11)
- XML (5)
- JDOM XML Parser (1)