Sunday, March 1, 2009

ArrayList/Iterators

/*** Programmer: Bocong, Wendel B.
Name of Program: ArrayList with IteratorsDate Started : March 2,2009
Date Ended: March 2,2009
Purpose: To try implementations that deals with ArrayList and Iterators.***/

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class iterators {
public static void main(String args[]) {
ArrayList<String> wen = new ArrayList<String>();

wen.add("Jessel Ann Abellana");
wen.add("Nerissa Agapay");
wen.add("Mixie Tulid");
wen.add("Rosedil Mobreros");
wen.add("Ana Mae Respecia");
wen.add("Wendel Bocong");

System.out.print("Original contents of wen: ");
Iterator<String> boc = wen.iterator();
while (boc.hasNext())
{
String element = boc.next();
System.out.print(element + " ");
}

System.out.println();

ListIterator<String> del= wen.listIterator();
while (del.hasNext())
{
String element = del.next();
del.set(element + "+");
}

System.out.println("Size of wen after additions: " + wen.size());
wen.remove(1);

{
System.out.println("Size of wen after deletions: " + wen.size());
System.out.println("Contents of wen: " + wen );
}
}
}


Things I learned in this exercise:

  • the implementation of array list is more comprehensive compared to array.

No comments:

Post a Comment