java.util.ArrayDeque.clone() 方法返回此deque佇列的副本。
以下是java.util.ArrayDeque.clone()方法的宣告
public ArrayDeque<E> clone()
NA
此方法返回此deque佇列的副本。
NA
下面的範例演示java.util.ArrayDeque.getFirst()方法的用法。
package com.yiibai; import java.util.ArrayDeque; import java.util.Deque; public class ArrayDequeDemo { public static void main(String[] args) { // create an empty array deque with an initial capacity ArrayDeque<Integer> deque1 = new ArrayDeque<Integer>(8); // use add() method to add elements in the deque deque1.add(15); deque1.add(30); deque1.add(20); deque1.add(18); // clone the first deque, Deque<Integer> deque2 = deque1.clone(); // let us print all the elements available in deque2 // now deque2 should have similar elements to deque1. for (Integer number : deque2) { System.out.println("Number = " + number); } } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
Number = 15 Number = 30 Number = 20 Number = 18