标签:log static 实例 rri ++ 支持 except system generated
定义:
提供一种方法顺序访问一个聚合对象中各个元素,而又不需暴露该对象的内部表示
应用场景:
public interface Iterator { public boolean hasNext(); public Object next(); public boolean remove(); } public class MyIterator implements Iterator { String[] dataArray = null; int point = 0; int size = 0; public MyIterator(String[] dataArray, int size) { this.dataArray = dataArray.clone(); this.size = size; } @Override public boolean hasNext() { return point < size ? true : false; } @Override public Object next() { // TODO Auto-generated method stub if (point <= size) { point++; return dataArray[point - 1]; } else { throw new NullPointerException(); } } @Override public boolean remove() { // TODO Auto-generated method stub return false; } } public interface Iaggregate { public Iterator getIterator(); } public class AggregateA implements Iaggregate{ static String [] data=new String[100]; static{ data[0]="a"; data[1]="b"; data[2]="c"; data[3]="d"; data[4]="e"; data[5]="f"; data[6]="g"; } @Override public Iterator getIterator() { // TODO Auto-generated method stub return new MyIterator(data, 7); } } public class test { public static void main(String[] args) { Iterator it=new AggregateA().getIterator(); while(it.hasNext()){ System.out.println(it.next()); } } }
标签:log static 实例 rri ++ 支持 except system generated
原文地址:http://www.cnblogs.com/zhuangxr/p/6806071.html