package com.iterator;public class Node {
public Node(Object o, Node n) {
super();
this.o = o;
this.n = n;
}
private Object o;
private Node n;

public Object getO() {
return o;
}
public void setO(Object o) {
this.o = o;
}
public Node getN() {
return n;
}
public void setN(Node n) {
this.n = n;
}

}第二个类
package com.iterator;import java.util.ArrayList;
import java.util.List;public class LinkedList implements Collection{ Node head=null;
Node tall=null;
Node n=null;
int size=0;
//List<Node> lt = new ArrayList<Node>();
public void add(Object o){
n = new Node(o,null);
if(head==null){
head=n;
tall=n;
}

tall.setN(n);
tall=n;
size++;
}
public int size(){
return size;
}
@Override
public Iterator iterator() {

return new ArraylistIterator();
}
private class ArraylistIterator implements Iterator{
private int i=0;
@Override
public Object Next() {
Object o =n;
i++;
return o;
} @Override
public boolean hasNext() {
if(i >= size) return false;
return true;
}
}
}测试类
package com.iterator;public class Test { public static void main(String[] args) {
Collection ay = new LinkedList();

for(int i = 0; i< 15 ;i++){
ay.add(new Cat(i));
}
System.out.println(ay.size());
Iterator it = ay.iterator();
while(it.hasNext()){
Object o1 = it.Next();
System.out.println(o1+"\t");
}
}
}