In this chapter we will discuss the stack.
1. Features
Advanced, when an element is pressed into the stack, he will be at the bottom of the stack, and then, another pressure in, cover the original elements above, the original elements want to go out, only the above elements to the top of the stack before the opportunity.
2. Method Demo
Package Com.ray.ch09;import Java.util.arrays;import Java.util.stack;public class Test {public static void main (string[] args) {stack<integer> Stack = new stack<integer> (), for (int i = 0; i < i++) {stack.add (i);//actually use the add side The law is not exact}stack.push (12);//better use push, press stack System.out.println (arrays.tostring (Stack.toarray ())); System.out.println (Stack.pop ()); System.out.println (Stack.peek ()); System.out.println (Arrays.tostring (Stack.toarray ()));}}
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12]
12
9
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Note: Stack is a vector, so he has all the methods of the vector, but for the stack, add, remove and other methods are full of confusion, it is best to use push, pop, peek these methods to operate.
Summary: This chapter mainly describes the characteristics of the stack and points of attention.
This chapter is here, thank you.
-----------------------------------
Directory
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Know java-9.8 stack (stack) from scratch