Java ArrayDeque push()方法
java.util.ArrayDeque.push(E e) 此方法将元素压入此双端队列表示的堆栈上。
1 语法
public void push(E e)
2 参数
e:要放入双端队列的元素。
3 返回值
无
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.util.ArrayDeque.push(E e)方法的例子
*/
import java.util.ArrayDeque;
import java.util.Deque;
public class Demo {
public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque deque = new ArrayDeque(8);
// use add() method to add elements in the deque
deque.add(25);
deque.add(30);
deque.add(35);
// adding elements using push() method
deque.push(10);
deque.push(15);
System.out.println("Printing Elements after using push operation:");
for (Integer number : deque) {
System.out.println("Number = " + number);
}
}
}
输出结果为:
Printing Elements after using push operation:
Number = 15
Number = 10
Number = 25
Number = 30
Number = 35