Return an Object in Java
        Posted  
        
            by 
                digby12
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by digby12
        
        
        
        Published on 2012-04-11T11:24:45Z
        Indexed on 
            2012/04/11
            11:29 UTC
        
        
        Read the original article
        Hit count: 243
        
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.
© Stack Overflow or respective owner