import java.util.*;
//====================================================================
//Creating and using an ArrayList without generics
//====================================================================
@SuppressWarnings("unchecked")          //annotation to suppress compile warnings

public class ArrayList0 
{
    public static void main(String[ ] args) 
    {
        //Creating an ArrayList Collection class without using <generic> ------------

        ArrayList  mixed_data   = new ArrayList ( );

        mixed_data.add(1);               //primitive will auto convert to wrapper class,
        mixed_data.add(2);               //then will be stored as Object datatype

        mixed_data.add("Sunday");        //string will be stored as Object datatype
        mixed_data.add("Monday");

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

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

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

        int elem1   = (int) mixed_data.get(0);          //Must (cast) down
        int elem2   = (int) mixed_data.get(1);

        String elem3    = (String) mixed_data.get(2);   //Must (cast) down
        String elem4    = (String) mixed_data.get(3);       

        System.out.println("Content is: "+ elem1 +" "+ elem2 +" "+ elem3 +" "+ elem4);

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

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

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

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