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

  • SEARCH
  • Home
  • 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 7704493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:41:35+00:00 2026-05-31T23:41:35+00:00

My attempt to customize the method contains of ArrayList, I used Eclipse to generate

  • 0

My attempt to customize the method contains of ArrayList, I used Eclipse to generate these methods inside a class TaskCandidateListItemDo

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result;

    if (keyValue == null) {
        result += 0;
    } else {
        result += keyValue.hashCode();
    }

    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }

    TaskOverrideItemDo other = (TaskOverrideItemDo) obj;

    if (keyValue == null) {
        if (other.keyValue != null) {
            return false;
        }
    } else if (!keyValue.equals(other.keyValue)) {
        return false;
    }
    return true;
}

And here’s is how I use it

taskCandidateList = (List<TaskCandidateListItemDo>) namedQuery.list();

for (TaskOverrideItemDo taskOverrideItemDo : validateOverrideListSearchCriteriaDo
        .getTaskOverrideItemDoList()) {

    if (taskCandidateList.contains(taskOverrideItemDo.getKeyValue())) {
       // do some code
    }
}

My list declared as followed

private List<TaskCandidateListItemDo> taskCandidateList;

The // do some code inside the if statement is never executed even if keyValue exist. Also, the break point wouldnt stop at the equals method..

  • 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-31T23:41:36+00:00Added an answer on May 31, 2026 at 11:41 pm

    Try with:

    if (taskCandidateList.contains(taskOverrideItemDo)) {
    

    Without getKeyValue(), I suppose it returns the value of the field keyValue (and your equals method compares only TaskCandidateListItemDo because of:

    if (getClass() != obj.getClass()) {
        return false;
    }
    

    As alternative you may support comparison with the type of keyValue inside the equals method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I attempt to use webservice return POCO class generated from entity data model as
In attempt to explain that arrays are just pointers (in C++) to our class,
First attempt to use this cool site - after searching for 2 hours: So
In an attempt to wrap some unmanaged code in a managed .dll I'm trying
Why does this attempt at creating a list of curried functions not work? def
When I attempt to debug a simple program with gdb on cygwin I get
I'm attempt to call a C++ dll with a struct and function like struct
in my attempt to learn a bit faster the use of spring and hibernate
this if my first attempt at using streaming for WCF, and I am struggling
In an attempt to learn to use PInvoke in C#, I'm a little unsure

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.