/** This program is intended to be used with the book "Java 6 -- What Do You Want To Do?"
 * by Steven P. Warr and is distributed free of charge and without and expectations of remuneration.
 * Chapter DAT   NOTE most program names begin with the title of the chapter in which
 * they are intended to be used.   Copyright 2010 Steven P. Warr All rights reserved
	ArrayList Example.
 */

import java.io.*;   		//needed so you can use the File class
import java.util.*;  		//needed for Lists
public class Dat01
{
	public static void main(String[ ] args) throws IOException
		{
			//ArrayList <Integer>a = new ArrayList () ;  // This will generate
			                                           // the error below
			//Note: H:\Java6\code\pDAT01.java uses unchecked or unsafe operations.
            //Note: Recompile with -Xlint:unchecked for details.
            
            //ArrayList b = new ArrayList();  //works, but will require the use
                                              //of a wrapper class to access.
                                              //see lines 31 - 33
            
            ArrayList <Integer> c = new ArrayList <Integer>();   //Best                               
			c.add(2);                         // adds  number to the end of the list                     
			c.add(4);                                              
			c.add(6);                                              
			c.add(8);                                              
			c.add(10);                                              
			c.add(12);
			
			int num = c.get (3);              // error if type not specified
			//int num = (String)c.get (3);   // Wrapper class cast
			System.out.println(num);                                              

			System.out.println(c);    //[2,4,6,8,10,12]                                          
            c.add(2,13);                   //13 is inserted at #2 location
			System.out.println(c);    //[2,4,13,6,8,10,12] 
			c.set(4,15);                   //15 overwrites position #4                                    
			System.out.println(c);    //[2,4,13,6,15,10,12] 
			System.out.println(c.size()); //number of items in the list 
            c.remove(2);            // removes the 13     
			System.out.println(c);    //[2,4,13,6,15,10,12] 
			System.out.println("\nThe list");
			for(Integer x:c)
			    System.out.println(x);   // for - each automates get 
            
            
        }

}
