import java.util.*;
//*****************************************************************************
// Convert int array to Integer, and back again
// Convert Integer array to List, and back again                            
//*****************************************************************************

public class xConvert   
{
    public static void main(String[] args)
    {
       int[] array1 = {1,2,3,4,5};                                          //create an load an int array
       System.out.println("int array:\t\t" + Arrays.toString(array1));

    //-- Copy int array to Integer array --------------------------------------

       Integer[] array2 = new Integer[array1.length];                       //create Integer array of same size
       for (int i=0; i<array1.length; i++)                                  //copy int array to Integer
           array2[i] = array1[i];                                         
       System.out.println("Converted to Integer:\t" + Arrays.toString(array2));
     
    //-- Copy Integer array to int array --------------------------------------

       int[] array3 = new int[array2.length];                               //create int array of same size
       for (int i=0; i<array2.length; i++)                                  //copy Integer array to int
           array3[i] = array2[i];                                         
       System.out.println("Converted back to int:\t" + Arrays.toString(array3));

       System.out.println();
 
    //-- Create Integer array -------------------------------------------------

       Integer[] array4 = {1,2,3,4,5};                                      //create and load an Integer array
       System.out.println("Integer array:\t\t"  + Arrays.toString(array4));
 
    //-- Create an Integer List and load it from an array ---------------------

       List<Integer> list = Arrays.asList(array4);                          //convert Integer array to Integer List
       System.out.println("Converted to List:\t"  + list);
 
    //-- Create an Integer array and load it from a list ----------------------

       Integer[] array5 = new Integer[0];                                   //create an array (of any size)
       array5 = list.toArray(array5);                                       //convert a Integer List to an array
       System.out.println("Convertd back to array:\t" + Arrays.toString(array5));
    }
}