1 3 package jodd.util.collection; 4 5 import java.util.LinkedList ; 6 7 10 public class SimpleStack { 11 12 private LinkedList list = new LinkedList (); 13 14 19 public void push(Object o) { 20 list.addLast(o); 21 } 22 23 28 public Object pop() { 29 if (list.isEmpty()) { 30 return null; 31 } 32 return list.removeLast(); 33 } 34 35 36 public Object [] popAll() { 37 Object [] res = new Object [list.size()]; 38 for (int i = 0; i < res.length; i++) { 39 res[i] = list.get(i); 40 } 41 list.clear(); 42 return res; 43 } 44 45 50 public Object peek() { 51 return list.getLast(); 52 } 53 54 55 60 public boolean isEmpty() { 61 return list.isEmpty(); 62 } 63 64 69 public int size() { 70 return list.size(); 71 } 72 73 } 74 | Popular Tags |