/*
Programmer: Mary Rose M. Celmar
Date Started: 03-04-09
Date Ended: 03-04-09
Purpose: to learn about iterator
*/
class WithData{
private Treeset<>m_data=new Treeset
public void add(int in)
{
m_data.add(in);
}
public Collection get_data()
{
return m_data;
}
}
class Demo{
public static void main (String [] args){
WithData some_object=new WithData ();
for (int i=9;i>0;--1)
some_object.add(i);
Collection data =some_object.get_data();
for (java.util.Iterator it=data.iterator();it.hasNext();)
System.out.print(it.next() + " ");
}
}
output:
1 2 3 4 5 6 7 8 9
I Learned about:
* three methods of iterator which is optional. The it.hasNext(), it.next(), and it.remove().
* Iterator are created by calling the iterator() or listIterator() method.
* listIterator Methods . the it.hasPrevious(), it.previous(),itnextIndex(), it.previousIndex(), it.add(obj), it.set(),and it.remove()
Tuesday, March 3, 2009
Iterator
Subscribe to:
Post Comments (Atom)
Sorry sir don.. wala ko kareport sa iterator. emergency man gud. ni uli ko sa lupon kay gipatawag ko sa DORECO office. gipangita man gud ang disconnection order sa consumer. ready na unta ko ato ug report sir don. pero karon nakalimot na pud ko...hehhe pasensya na sir..
ReplyDelete