Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:15+00:00 2026-05-23T07:36:15+00:00

Ive been searching for a robust way to compare my objects, I came across

  • 0

Ive been searching for a robust way to compare my objects, I came across the ObjectUtils , and had the immidiate doubt that would it be able to compare it efficiently or not as I do not know how it works internally and documentation on apache org site about this is scarce.

Can someone please help me with this??

EDIT:

When I say compare , all I really need to to compare for equality of MYOBJ, where MYOBJ is a custom object I have defined , which has various variables in it(all these vars are primitive data types like int,long,float String which can be compares in a straightforward manner if they are not null), but this might change in the future.

I was not sure would BeanUtils.areEqual method be able to handle such a case and what if I include my own datatypes(non -primitives) inside this MYOBJ.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:36:16+00:00Added an answer on May 23, 2026 at 7:36 am

    Your Question is very vague, I don’t really know what you are talking about, so I’ll go in several Directions.

    “compare my Objects” can mean several things. In Java, this usually means comparing them for sorting, i.e. through the Comparable / Comparator interfaces. While ObjectUtils does provide a null-safe compare method, it won’t help you beyond that. What you need is either a custom Comparator or for your objects to implement Comparable. CompareToBuilder can help you with both, to a certain extent:

    public class SomeBean implements Comparable<SomeBean>{
    
        private String foo;
        private int bar;
        private List<String> baz;
    
        public int compareTo(SomeBean other) {
            return new CompareToBuilder()
            .append(foo, other.foo)
            .append(bar, other.bar)
            .append(baz, other.baz)
            .toComparison();
        }
    
    }
    

    If, on the other hand, you want to compare the properties of different object types, then you are looking in the totally wrong direction. Have a look at Commons / BeanUtils instead. Sample code:

    public class BeanUtilsTester {
    
        public static class Foo{
            private String foo="foo";
            public String getFoo() {return foo;}
            public void setFoo(String foo) {this.foo = foo;}
            private Integer bar=123;
            public Integer getBar() {return bar;}
            public void setBar(Integer bar) {this.bar = bar;}
            private List<String> squoggle=Arrays.asList("abc","def");
            public List<String> getSquoggle() {return squoggle;}
            public void setSquoggle(List<String> squoggle) {this.squoggle = squoggle;}
        }
    
        public static class Bar{
            private String foo="bar";
            public String getFoo() {return foo;}
            public void setFoo(String foo) {this.foo = foo;}
            private Integer bar=456;
            public Integer getBar() {return bar;}
            public void setBar(Integer bar) {this.bar = bar;}
            private String[] fiddle=new String[]{"abc","def"};
            public String[] getFiddle() {return fiddle;}
            public void setFiddle(String[] fiddle) {this.fiddle = fiddle;}
        }
    
        public static void main(String[] args) throws Exception{
            Foo foo = new Foo();
            Bar bar = new Bar();
            Map<String,Object> fooProps = BeanUtils.describe(foo);
            Map<String,Object> barProps = BeanUtils.describe(bar);
            fooProps.keySet().retainAll(barProps.keySet());
            BeanUtils.populate(bar, fooProps);
            assertEquals(foo.getFoo(),bar.getFoo());
            assertEquals(foo.getBar(), bar.getBar());
        }
    
    }
    

    And if you just want to implement equals() correctly, look at EqualsBuilder:

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SomeBean) {
            SomeBean other = (SomeBean) obj;
            return new EqualsBuilder()
                    .append(foo, other.foo)
                    .append(bar, other.bar)
                    .append(baz, other.baz)
                    .isEquals();
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How exactly do we use Android's MonthDisplayHelper? Ive been searching for possible widgets/views that
Ive been searching for an answer for this and cant find one, although I
I've been searching around, and I haven't found how I would do this from
I've been searching for a library that can render organisation charts in either flash
I've been searching for information for a common kernel implementation of queues, that is,
I've been searching the net hard for some javascript code that allows me to
Ive been searching for a solution for hours and my question is really simple.
I've been searching the web for a way to do this without much success,
I've been searching the internet a lot for UML modeling tools that support version
I've been searching long for clear informations about the right way of extending ItemizedOverlay

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.