这是我的代码:
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
public class ArrayDequeDemo {
public static void main(String[] args) {
// create an empty array deque with an initial capacity
Deque<Integer> deque = new ArrayDeque<Integer>(8);
// use add() method to add elements in the deque
deque.add(15);
deque.add(30);
deque.add(20);
deque.add(18);
// let us print all the elements available in deque
for (Integer number : deque) {
System.out.println("Number = " + number);
}
//Collections.shuffle((List<?>) deque);
// getFirst() will retrieve element at first(head) position
int retval = deque.getFirst();
System.out.println("Retrieved Element is = " + retval);
}
}
我知道如何洗牌 a List
,但我如何使用Collections
洗牌双端队列?请用代码回复,因为我不完全习惯 Java 术语/理论,我还在学习。