List与数组之间的相互转换
@Test
public void test2() {
int[] array = { 12, 12, 1, 2 };
System.out.println(Arrays.toString(array));
List<Integer> list = Arrays.asList(12, 12, 1, 2, 2);
System.out.println(list);
Integer[] array2 = new Integer[list.size()];
array2 = list.toArray(array2);
System.out.println(Arrays.deepToString(array2));
}
@Test
public void testStack() {
Stack<Integer> stack = new Stack<Integer>();
stack.push(5);
stack.push(6);
stack.push(7);
stack.push(8);
System.out.println(stack);
int size = stack.size();
for (int i = 0; i < size; i++) {
Integer t = stack.pop();
System.out.println("取出的数据" + t);
System.out.println("取完后剩余的数据" + stack);
}
}
@Test
public void testQueue() {
Queue<Integer> queue = new ArrayDeque<Integer>();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
int size = queue.size();
for (int i = 0; i < size; i++) {
Integer t = queue.poll();
System.out.println("被移除的" + t);
System.out.println("剩下的" + queue);
}
}