importjava.util.PriorityQueue;importjava.util.Queue;importjava.util.Stack;importjava.util.concurrent.ArrayBlockingQueue;publicclass quit {
publicstaticvoidmain(String[] args){
//后进先出//Stack<String> stackstr = new Stack<>();先进先出Queue<String> queue =newArrayBlockingQueue<>(12*48+12);
queue.add("1236");
queue.add("1235");
queue.add("1234");
queue.remove("1236");System.out.println(queue.poll());System.out.println(queue.poll());System.out.println(queue.poll());//后进先出Stack<Integer> stack =newStack<>();//压栈
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);//stack.remove(3);//查看栈顶元素System.out.println(stack.peek());//出栈int ret = stack.pop();System.out.println(ret);//4
ret = stack.pop();System.out.println(ret);//3
ret = stack.pop();System.out.println(ret);//2
ret = stack.pop();System.out.println(ret);//1//判断栈是否为空System.out.println(stack.empty());//此时栈为空 如果 查看栈顶元素 或者 出栈 会报异常(EmptyStackException)System.out.println(stack.peek());System.out.println(stack.pop());}}
运行结果
12351234null44321trueException in thread "main"java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at zhen.qi.text.quit.main(quit.java:49)Process finished withexit code 1