code fragment we give java implementation of this algorithm incidentallythis method also illustrates how we can use generic types in simple application that uses generic stack in particularwhen the elements are popped off the stack in this examplethey are automatically returned as elements of the typehencethey can be immediately returned to the input array we show an example use of this method in code fragment code fragment generic method that reverses the elements in an array of type objectsusing stack declared using the stack interface code fragment test of the reverse method using two arrays