Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Checking to see if two Integer values are Equal

843789Mar 21 2009 — edited Mar 21 2009
Hi guys

I am working on a project and I've come to a stage where I need to compare two integer values.

Here is the code for the method:
public Domestic findDomProperty(int reference) {
        Domestic d1;
        int indexLocation = -1;
        for (int i = 0; i < super.size(); i++) {
            d1 = (Domestic)super.elementAt(i);
            if (d1.getReference().equal(reference)) {
                indexLocation = i;
                break;
            }
        }

        if (indexLocation == -1) {
            return null;
        }
        else {
            return (Domestic)super.elementAt(indexLocation);
        }
    }
I get the error on the compare link:
if (d1.getReference().equal(reference)) {
The error (in NetBeans 6.5) say:

"int cannot be dereferenced"

gerReference returns an int and I'm guessing { .equal() } does not work on ints ! (please correct me if I'm wrong).

What I want to know is .. what do I use instead of { .equals() } to compare the two integer values.

I would greatly appreciate any help.

Thank You.

Edited by: Ciwan86 on Mar 21, 2009 6:56 PM

Edited by: Ciwan86 on Mar 21, 2009 6:56 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2009
Added on Mar 21 2009
3 comments
316 views