package com.mindprod.example;
import java.util.ArrayList;
import java.util.Iterator;
import static java.lang.System.*;
/**
* example use of Iterable.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestIterable implements Iterable<String>
{
/**
* internal ArrayList of seed varieties
*/
private final ArrayList<String> a = new ArrayList<>( 10 );
{
a.add( "pinecone" );
a.add( "apple seed" );
a.add( "peach pit" );
a.add( "cocoanut" );
a.add( "acorn" );
}
/**
* Sample code to TestIterable. Needs JDK 1.8+
*
* @param args not used
*/
public static void main( String[] args )
{
TestIterable t = new TestIterable();
for ( String s : t )
{
out.println( s );
}
}
/**
* iterator for entire class, just iterates over internal arrayList
*
* @return Iterator over entire class
*/
public Iterator<String> iterator()
{
return a.iterator();
}
}