Xavier Johanis
Xavier Johanis

Reputation: 59

The operator < is undefined for the argument type(s) java.lang.Integer, java.lang.Integer

public TreeNode find(Integer data){
    if (this.data == data)
        return this;
    if (data < this.data && leftChild != null)
        return leftChild.find(data);

    if (rightChild != null)
        return rightChild.find(data);
    return null;
}

Hi there!, so I've done some research about similar problems and tried most of the suggestions and still nothing. I would like to know how to solve this problem because I've been stuck for a couple of hours now.

Thank you in advance :)

Upvotes: 0

Views: 4651

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198211

A couple solutions:

  • data.compareTo(this.data) < 0
  • data.intValue() < this.data.intValue()

Generally speaking, you can't use < on boxed integers. Additionally, == will do the wrong thing, so you should be writing

if (this.data.equals(data))
    return this;

or

if (this.data.intValue() == data.intValue())

Upvotes: 2

Related Questions