1 package com.gxf.collection;
 2 
 3 import java.util.LinkedList;
 4 
 5 public class TestForT<T> {
 6     private LinkedList<T> storage = new LinkedList<T>();
 7     
 8     /**
 9      * 压栈操作
10      * @param element
11      */
12     public void push(T element){
13         storage.addFirst(element);
14     }
15     /**
16      * 出栈
17      * @return
18      */
19     public T pop(){
20         return storage.removeFirst();
21     }
22     
23     /**
24      * 判断栈是否为空
25      * @return
26      */
27     public boolean isEmpty(){
28         return storage.isEmpty();
29     }
30 
31     public static void main(String[] args) {
32         TestForT<Integer> stack = new TestForT<Integer>();
33         stack.push(1);
34         stack.push(2);
35         stack.push(3);
36         stack.push(4);
37         stack.push(5);
38         
39         while(!stack.isEmpty()){
40             System.out.println(stack.pop());
41         }
42     }
43 
44 }

output:

5
4
3
2
1