/** 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
	LinkedList Example.
 */

import java.io.*;   		//needed so you can use the File class
import java.util.*;  		//needed for Lists
public class Dat02
{
	public static void main(String[ ] args) throws IOException
		{
			LinkedList <String>a = new LinkedList ();  // This will generate
			                                           // the error below
			//Note: H:\Java6\code\pDAT01.java uses unchecked or unsafe operations.
            //Note: Recompile with -Xlint:unchecked for details.
            
            //LinkedList b = new LinkedList();  //works, but will require the use
                                              //of a wrapper class to access.
                                              //see lines 31 - 33
            
            LinkedList <String> c = new LinkedList <String>();  //Best                                
			c.add("George");                         // adds  number to the end of the list                     
			c.add("John");                                              
			c.add("Martin");                                              
			c.add("Andrew");                                              
			c.add("Tippecanoe");                                              
			c.add("Abraham");
			
			String name = c.get (3);              // error if type not specified
			//String name = (String)c.get (3);   // Wrapper class cast
			System.out.println(name);                                              

			System.out.println(c);    		//[George, John, Martin, Andrew, Tippecanoe, Abraham]                                          
            
            c.addFirst("Teddy");      		//Teddy is inserted at #0 location
			System.out.println(c);    		//[Teddy, John, Martin, Andrew, Tippecanoe, Abraham]  
            c.addLast("Richard");      		//Richard is added to the end
			System.out.println(c);    		//[George, John, Martin, Andrew, Tippecanoe, Abraham, Richard] 
			c.set(4,"Franklin");                   //15 overwrites position #4                                    
			System.out.println(c);    //[George, John, Martin, Andrew, Franklin, Abraham, Richard]  
			System.out.println(c.size()); //number of items in the list 
            c.remove(2);            // removes Martin     
			System.out.println(c);    //[George, John, Andrew, Tippecanoe, Abraham, Richard] 
			System.out.println("\nThe list");
			for(String x:c)
			    System.out.println(x);   // for - each automates get 
            
        }

}
