DEV Community

Rajesh Mishra
Rajesh Mishra

Posted on

How to find out the differences between 2 objects in Java (2023)

In this post, we will showcase a step-by-step guide on how to detect and present distinctions between two java objects by leveraging a set of classes and interfaces provided by Apache Commons Lang.

Classes, Interfaces, and pom.xml
The classes and interfaces to be used for this post are as follows:

org.apache.commons.lang3.builder.Diff
org.apache.commons.lang3.builder.DiffResult
org.apache.commons.lang3.builder.DiffBuilder
org.apache.commons.lang3.builder.Diffable

Scenario
We have two Employee Object for our use case, and we need to list the differences between them. The list must show the affected field and the old-new (from Employee 1 to Employee 2 values.

Employee Object 1
For the Employee Object, we have the following data.

Name = Ankit
ID = 1
Designation = Assistant Vice President
Address = Mumbai
Employee Object 2
For the Employee Object, we have the following data.

Name = Ankit
ID = 1
Designation = Vice President
Address = Pune

Read complete tutorial

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay