Return an Object in Java
- by digby12
I've been struggling to work out how to return an object.
I have the following array of objects.
ArrayList<Object> favourites;
I want to find an object in the array based on it's "description" property.
public Item finditem(String description) {
for (Object x : favourites) {
if(description.equals(x.getDescription())) {
return Object x;
else {
return null;
Can someone please show me how I would write this code. Thanks.