Java的ArrayDeque clone() 方法
Java.util.ArrayDeque.clone() 方法用于返回此双端队列的浅拷贝。它只是创建双端队列的副本。
句法:
Array_Deque.clone()
参数:该方法不带任何参数。
返回值:该方法仅返回 ArrayDeque 的副本。
下面的程序说明了Java.util.ArrayDeque.clone() 方法:
方案一:
// Java code to illustrate clone()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
ArrayDeque de_que = new ArrayDeque();
// 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 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]
方案二:
// Java code to illustrate clone()
import java.util.*;
public class ArrayDequeDemo {
public static void main(String args[])
{
// Creating an empty ArrayDeque
ArrayDeque de_que = new ArrayDeque(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 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]