Not able to iterate ItemList from Transaction class
<p>This is my <code>Item</code> class:</p>

<pre><code>public class Item {

 private String id;
 private int count;
 private String  name;

public int getcount() {
   return this.count;
}

public Item(String name) {
     this.name=name;
     this.id = "";

 }

public Item(String id, String name) {
   this.name=name;
   this.id=id;
 }

public Item(int count) {
    this.count=count;
}

public String getItemName() {
    return this.name;
}

public String getItemId() {
    return this.id;
}

public Item returnItems(ItemList itemset) {
    Item item=null;
    return item;
  }
}
</code></pre>

<p>This is my <code>ItemList</code> class which will contain a <code>List</code> of <code>items</code>:</p>

<pre><code>public  class ItemList implements Iterable&lt;Item&gt;  {

  private List&lt;Item&gt; hold=new ArrayList&lt;Item&gt;();



  ItemList(Item item) {
    this.hold.add(item);
  }

  ItemList() {
    //throw new UnsupportedOperationException("Not yet implemented");
  }


  public List&lt;Item&gt; getItemSet() {
    return this.hold;
  }


  public void addItems(Item item) {
    this.hold.add(item);
  }


  @Override
  public Iterator&lt;Item&gt; iterator() {
    Iterator&lt;Item&gt; item = hold.iterator();
    return item;
  }
}
</code></pre>

<p>This is the <code>Transaction</code> class:</p>

<pre><code>public class Transaction implements Iterable {

 private List&lt;ItemList&gt; trans=new ArrayList&lt;ItemList&gt;();

 public List&lt;Item&gt; getUniqueItems() {

    Database d = new Database();
    List&lt;Item&gt; unique = new ArrayList&lt;Item&gt;();

    String query="Select id,name from item";
    ResultSet rs = d.sendQuery(query);
    try {
        while(rs.next()) {
           // System.out.println(rs.getString(1)+"\t"+rs.getString(2));
            unique.add(new Item(rs.getString(1),rs.getString(2)));
        }
    }
    catch(Exception e){
        System.out.print(e.getMessage());
    }
    return unique;
}

public ItemList getUniqueItem() {
     ResultSet rs;
     Database d=new Database();
     ItemList unique=new ItemList();
      String query="Select id,name from item";
      rs=d.sendQuery(query);
        try{
        while(rs.next())
         {
           //System.out.println(rs.getString(1)+"\t"+rs.getString(2));
           Item item=new Item(rs.getString(1),rs.getString(2));
           unique.addItems(item);
    }

    } catch(Exception e) {
       System.out.print(e.getMessage());
    }

    return unique;
}


public void addTransaction(ItemList itemList) {
     this.trans.add(itemList);
}

public List&lt;ItemList&gt; getTransaction() {
     return this.trans;
}

@Override
public Iterator&lt;ItemList&gt; iterator() {
    Iterator&lt;ItemList&gt; itemList = trans.iterator();
    return itemList;
}

public int countItems(ItemList itemList) {
      ResultSet rs;
      Database d=new Database();
      String query="";
      int count=0;
      for(Item i:itemList)
     {
       System.out.println(i);
       String id=i.getItemId();
        System.out.print(id+"\t");
        query="SELECT count(*) FROM `item_transaction` where item_id="+id;
          rs=d.sendQuery(query);
          try{
           while(rs.next())
          {
              System.out.print(rs.getString(1));
              count=Integer.parseInt(rs.getString(1));
              System.out.print(count+"\t");
          }

          }catch(Exception e){}
   }

      return count;
 }

 }
</code></pre>

<p>And this is my <code>main</code> class:</p>

<pre><code>public class Ap {

public static void main(String args[])
{
   Transaction t=new Transaction();
    Transaction Ci=new Transaction();
   Transaction Li=new Transaction();

    List&lt;Item&gt; list = t.getUniqueItems();
    for(Item i:list)
    {
        ItemList itemList=new ItemList(i);
        Ci.addTransaction(itemList);
    }

}
</code></pre>

<p>After adding <code>itemList</code> to <code>Transaction</code>, I want to iterate over <code>Ci</code> and pass <code>itemList</code> to the <code>countItems</code> method in the <code>Transaction</code> class.</p>

<p>I tried:</p>

<pre><code>for(ItemList list:Ci) {
    int x=t.countItems(list);
}
</code></pre>

<p>But am getting:</p>

<pre><code>found  java.lang.Object
      Required ItemList
</code></pre>

<p>Or do I have to get the <code>List&lt;ItemList&gt;</code> from the <code>Transaction</code> class and then iterate?</p>
