Hallo,
I have an arraylist containing objects. I would like to iterate it and confront one of the properties ("name") of the object with a string. If they match I return the object.
I don't know how to compare the present object property of the iteration with the string, and how to return the matching one.
The code I have till now:
I have an arraylist containing objects. I would like to iterate it and confront one of the properties ("name") of the object with a string. If they match I return the object.
I don't know how to compare the present object property of the iteration with the string, and how to return the matching one.
The code I have till now:
Code:
public myObject find(String criteria)
{
int i=1;
Iterator<myObject> it = this.myArrayList.iterator();
while (it.hasNext())
{
if (((it.next())).equals(criteria)¨
{return ...?...}
else
i++;
}