队列头文件:
import java.util.Queue;
import java.util.LinkedList;
定义队列:
Queue<Integer> queue = new LinkedList<Integer>();
复制队列:
方法一
queue.addAll(queue2)
/**
* Removes all of this collection's elements that are also contained in the
* specified collection (optional operation). After this call returns,
* this collection will contain no elements in common with the specified
* collection.
* /
根据官方的解释已经很明确了,这里queue是添加了queue2的所有值,并且queue里面如果原来有值则会全部删除,可以实现复制操作。
方法二
Queue<Integer> queue = new LinkedList<Integer>(queue2);
直接通过队列的构造函数生成新的队列,这也实现了队列的拷贝