Array array = new Array();
array.add( "cat" );
array.add( "dog" );
array.add( "emu" );
array.add( "dog" );
array.add( "dog" );
ArrayIterator i = array.begin();
while ( true )
{
i = (ArrayIterator)Finding.find( i, array.end(), "dog" );
if ( i.atEnd() ) // A simpler way: if ( i.equals( array.end() ) )...
break;
System.out.println
(
"iterator found " + i.get() + " at index " + i.index()
);
i.advance();
}
int intArray[] = { 3, 6, 2, 1, 8, 9, 4, 5 };
IntIterator j = (IntIterator)Finding.findIf
(
IntIterator.begin( intArray ),
IntIterator.end( intArray ),
new BindSecondPredicate( new GreaterNumber(), new Integer( 7 ) )
);
System.out.println
(
"First element > 7 is " + j.get() + " at index " + j.index()
);
DList list = new DList();
list.add( "cat" );
list.add( "dog" );
list.add( "emu" );
list.add( "emu" );
list.add( "dog" );
DListIterator k = (DListIterator)Finding.adjacentFind( list, new com.objectspace.jgl.predicates.EqualTo() );
System.out.println
(
"First consecutive sequence: " + k.get() + " at index " + k.index()
);