Generic is
Thought Analysis: Since the stack structure is implemented using a generic model, it cannot be used.
The Code is as follows:
Stack. java:
package cn.edu.xidian.crytoll;import java.util.LinkedList;public class Stack<T> { private LinkedList<T> container = new LinkedList<T>(); public void push(T t) { container.addFirst(t); } public T pop() { return container.removeFirst(); } public boolean empty() { return container.isEmpty(); }}
StackTest. java:
Package cn.edu. xidian. crytoll; public class StackTest {public static void main (String [] args) {Stack <String> stack = new Stack <String> (); System. out. println ("adding a string to the stack:"); System. out. println ("video learning Java"); System. out. println ("Java"); System. out. println ("Java from entry to entry (version 2nd)"); stack. push ("video learning Java"); // Add a String stack to the stack. push ("Java"); // Add a String stack to the stack. push ("Java from entry to entry (version 2nd)"); // Add the string System to the stack. out. println (" Extract the string from the stack: "); while (! Stack. empty () {System. out. println (String) stack. pop (); // delete all elements in the stack and output them in parallel }}}
Effect