Java.util.ArrayDeque.clone()方法用於返回此雙端隊列的淺拷貝。它隻是創建雙端隊列的副本。
用法:
Array_Deque.clone()
參數:該方法不帶任何參數。
返回值:該方法僅返回ArrayDeque的副本。
下麵的程序演示了Java.util.ArrayDeque.clone()方法:
示例1:
// Java code to illustrate clone()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
ArrayDeque<String> de_que = new ArrayDeque<String>();
// Use add() method to add elements into the Deque
de_que.add("Welcome");
de_que.add("To");
de_que.add("Geeks");
de_que.add("4");
de_que.add("Geeks");
// Displaying the ArrayDeque
System.out.println("ArrayDeque: " + de_que);
// Creating another array to copy
Deque<String> copy_deque = de_que.clone();
// Displaying the copy of Deque
System.out.println("The cloned array is: " + copy_deque);
}
}
輸出:
ArrayDeque: [Welcome, To, Geeks, 4, Geeks] The cloned array is: [Welcome, To, Geeks, 4, Geeks]
示例2:
// Java code to illustrate clone()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
ArrayDeque<Integer> de_que = new ArrayDeque<Integer>(8);
// Use add() method to add elements into the Deque
de_que.add(10);
de_que.add(15);
de_que.add(30);
de_que.add(20);
de_que.add(5);
// Displaying the ArrayDeque
System.out.println("ArrayDeque: " + de_que);
// Creating another array to copy
Deque<Integer> copy_deque = de_que.clone();
// Displaying the copy of Deque
System.out.println("The cloned array is: " + copy_deque);
}
}
輸出:
ArrayDeque: [10, 15, 30, 20, 5] The cloned array is: [10, 15, 30, 20, 5]
相關用法
- Java ArrayDeque contains()用法及代碼示例
- Java ArrayDeque add()用法及代碼示例
- Java ArrayDeque pop()用法及代碼示例
- Java ArrayDeque clear()用法及代碼示例
- Java ArrayDeque iterator()用法及代碼示例
- Java ArrayDeque offerFirst()用法及代碼示例
- Java ArrayDeque descendingIterator()用法及代碼示例
- Java ArrayDeque poll()用法及代碼示例
- Java ArrayDeque removeLastOccurrence()用法及代碼示例
- Java ArrayDeque removeFirstOccurrence()用法及代碼示例
- Java ArrayDeque removeFirst()用法及代碼示例
- Java ArrayDeque removeLast()用法及代碼示例
- Java ArrayDeque remove()用法及代碼示例
- Java ArrayDeque pollLast()用法及代碼示例
- Java ArrayDeque addLast()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 ArrayDeque clone() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。