//GenericMethodWithOneParameter.java
//You can have a generic method in a non-generic class.
//This program illustrates a generic method used to display
//the values in an array containing values of any type.

public class GenericMethodWithOneParameter
{
    //A generic method to display the values in any array
    public static <T> void printArray(T[] inputArray)
    {
        //Display array elements
        for (T element : inputArray)
        {
            System.out.printf("%s ", element);
        }
        System.out.println();
    }

    public static void main(String[] args)
    {
        System.out.println();

        //Create arrays of Integer, Double and Character
        Integer[] intArray =
        {
            1, 2, 3, 4, 5
        };
        Double[] doubleArray =
        {
            1.1, 2.2, 3.3, 4.4
        };
        Character[] charArray =
        {
            'H', 'E', 'L', 'L', 'O'
        };

        //Now display those arrays using the generic method
        System.out.println("Array integerArray contains:");
        printArray(intArray);
        System.out.println("\nArray doubleArray contains:");
        printArray(doubleArray);
        System.out.println("\nArray characterArray contains:");
        printArray(charArray);
    }
}
