Java ArrayDeque clone()方法
java.util.ArrayDeque.clone() 此方法返回此双端队列的副本。
1 语法
public ArrayDeque<E> clone()
2 参数
无
3 返回值
返回此双端队列的副本。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.util.ArrayDeque.clone()方法的例子
*/
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
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
热门文章
优秀文章