Wednesday, October 17, 2007

Java Library ArrayList


import java.io.PrintStream;
import java.util.*;

public class ReadAndReverse {

 
  static void readAndReverse (Scanner input, PrintStream output) {
   ArrayList L = new ArrayList ();
   while (input.hasNext())
    L.add(input.next());
   for (int k = L.size() - 1; k >= 0; k -=1)
    output.printf("%s ", L.get(k));
  }
  
  public static void main (String [] args) {
   Scanner inp = new Scanner (System.in);
   readAndReverse (inp, System.out);
  }
}

1 comment:

javin paul said...

Great article and you have indeed covered the Java Array list in great detail with code example. this is one of most useful class java API provides to us and detail knowledge of it really helps. I have also blogged about Java Arraylist in Java 5 some time back , may be you find interesting.

Just some daily notes ...

Powered By Blogger