contains method still not validating properly? any problem my bean class

contains method still not validating properly

in the chargelist i have charges 162,620;

chargelist contains other than 620 i.e 162 chargeid exists in the list why it is not entering into if loop;


   if(chargesList!=null && chargesList.size()>0)
            {
    if (!chargesList.contains( new HouseDocumentCharges("620")) )
    {
                        userInputModel = new UserInputModel(vndrList,"vendorIdLabel", ValidationConstants.MULTI_VENDOR_VALIDATION_NAME,4);//changed validation code from 3 to 4
                        validationModel.addUserInput("Vendor(s)",userInputModel);
    }


 any problem my bean class

public class HouseDocumentCharges implements Serializable,Cloneable
{

      public String            costIncurredAt;
      
      public String            chargeId;
      public String            chargeDescription;
      

       public HouseDocumentCharges(String chargeId) {
       this.chargeId = chargeId;
   }

  public boolean equals(Object obj) {
       return chargeId.equals( ((HouseDocumentCharges)obj).chargeId );
   }
   public int hashCode() {
       return chargeId.hashCode();
   }

}
    }
LVL 20
chaitu chaituAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
>     if (!chargesList.contains( new HouseDocumentCharges("620")) )

your if conditions is "if list does not contain '620'", which is false as it does contain "620"

> then what is the solution.......................

Depends on what condition you want it to be true
0
 
objectsCommented:
because it contains an element with chargeid=620
0
 
chaitu chaituAuthor Commented:
but chargeList also contains 162 chargeid naa...
0
 
chaitu chaituAuthor Commented:
then what is the solution.......................
0
 
objectsCommented:
fpr example if you want it to return true if it contains 620 or 621 then use:

    if (chargesList.contains( new HouseDocumentCharges("620")) ||
        chargesList.contains( new HouseDocumentCharges("621"))  )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.