import java.util.*;
//====================================================================
//Creating and using an ArrayList with generics
//====================================================================
public class ArrayList1 
{
    public static void main(String[ ] args) 
    {
        //Creating an ArrayList Collection class using <generic> ------------

        ArrayList<String> days_of_week  = new ArrayList<String>( );

        days_of_week.add("Sunday");                 //adding elements of Object type
        days_of_week.add("Monday");
        days_of_week.add("Tuesday");
        days_of_week.add("Wednesday");
        days_of_week.add("Thursday");
        days_of_week.add("Friday");
        days_of_week.add("Saturday");

        //Printing collection content ---------------------------------------

        System.out.println(days_of_week);               //calls the toString( ) method
        System.out.println( );                          // [Sunday, Monday, ... ]

        //Accessing individual elements -----------------------------------

        String d = days_of_week.get(0);                 //No need to cast down
        System.out.println("The first day is: " + d);

        //Using the for loop -------------------------------------------------

        for (int i=0; i<days_of_week.size( ); i++)
        {
            System.out.println(days_of_week.get(i) ); 
        }
        System.out.println( );

        //Using the enhanced for loop -------------------------------------

        for (String day : days_of_week)     //if not using generics, 
        {                                   //we need to retrieve using an Object
            System.out.println(day); 
        }
    }
}