Assuming number is what makes any instance of your class "unique" for the purpose of comparison, you should consider overriding the equals and hashCode methods.
That way, you'll be able to find instances of your class within a collection such as an ArrayList using indexOf(Object o);
For example:
public class ExampleClass
{
private int number;
public ExampleClass(int number)
{
this.number = number;
}
public int getNumber()
{
return number;
}
public void setNumber(int number)
{
this.number = number;
}
@Override
public boolean equals(Object other)
{
boolean isEqual = false;
if (other instanceof ExampleClass)
{
ExampleClass otherEC = (ExampleClass)other;
isEqual = number == otherEC.number;
}
return isEqual;
}
@Override
public int hashCode()
{
return number;
}
}
and
public static void main(String[] args)
{
List<ExampleClass> list = new ArrayList<ExampleClass>();
ExampleClass ec1 = new ExampleClass(1);
list.add(ec1);
list.add(new ExampleClass(3));
list.add(new ExampleClass(102));
System.out.println(list.indexOf(new ExampleClass(3)));
System.out.println(list.indexOf(new ExampleClass(1)));
System.out.println(list.indexOf(ec1));
System.out.println(list.indexOf(new ExampleClass(5)));
}
Will produce the following output:
1
0
0
-1
Please look here for more information on why you should override equals and hashCode for objects that you want to store in collections:
Why do I need to override the equals and hashCode methods in Java?