Programmer:Jenelyn Dongiapon
Program Name: Array and Iterators
Date: march 20,2009
import java.util.ArrayList;
import java.util.Iterator;
import java.lang.Object;
import java.util.ListIterator;
public class iterator1
{ public static void main(String args[])
{
ArrayList list = new ArrayList( 100 );
list.add( "miat" );
list.add( "yhang" );
list.add( "peu" );
list.add( "mhine" );
System.out.print("list: ");
Iterator list2 =list.iterator();
while (list2.hasNext())
{
Iteratorelement =list2.next();
System.out.print(element + " ");
}
System.out.println();
ListIterator list3 =list.listIterator();
while (list3.hasNext())
{
Iteratorelement=list3.next();
list3.set(element + "+");
}
System.out.println("before additions: " + list.size());
list.remove(1);
{
System.out.println("after deletions: " + list.size());
System.out.println("new lists: " + list );
}
}
}
Things I learned:
1. Arraylist cannot be applied in primitive data types.
2. Arraylist is modified version of array.
3. Iterators is use to manipulate arraylist.
Friday, March 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment