Sunday, March 1, 2009

Programmer: Ana Mae B. Respecia

Title of Code: ArrayListNumbers

Description: Enables Array  List and this program executes the hasPrevious that enables letters to form backwards...


CODE:

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


public class ArrayListABCD{
  public static void main(String args[]) {
  ArrayList al = new ArrayList();

  al.add("1");
  al.add("2");
  al.add("3");
  al.add("4");
  al.add("5");
  al.add("6");

  System.out.print("Original contents of al: ");
  Iterator itr = al.iterator();
  while (itr.hasNext()) {
  String element = itr.next();
  System.out.print(element + " ");
  }
  System.out.println();

  ListIterator litr = al.listIterator();
  while (litr.hasNext()) {
  String element = litr.next();
  litr.set(element + "+");
  }

  // Now, display the list backwards.

  System.out.print("Modified list backwards: ");
  while (litr.hasPrevious()) {
  String element = litr.previous();
  System.out.print(element  " ");
  }
  }
}


OUPUT OF THE CODE



Date: March 02, 2009

What i have learned:

  • ArrayList and Iterator are classes of java.util.
  • ArrayList cannot hold int.
  • Iterator is a class that can manipulate ArrayList
  • ArrayList is flexible, no need to specify an index.


No comments:

Post a Comment