想要将对象数组运行到通用构造函数中

时间:2013-02-06 03:33:32

标签: java object constructor

class CircularArrayDeque<E> implements Deque {
  private E[] items;
  private int currentSize, capacity, front, back;
  private static final int DEFAULT_CAPACITY = 10;

  public CircularArrayDeque(Collection<? extends E> other) {     
    items = (E[]) other.toArray();
    currentSize = other.size();
    front = 0;
    back = currentSize - 1;
  }
}
public static void main(String[] args) {

    int[] arr = {8, 7, 5, 3, 6, 7, 12, 4};
}

我希望能够将arr运行到构造函数CircularArrayDeque(arr)中。 Deque只是我写的一个界面,它不是java的类。如果可能的话,我不确定如何做到这一点。或者我可以将我的arr更改为对象整数,如.....

Integer[] arr = {8, 7, 5, 3, 6, 7, 12, 4};

1 个答案:

答案 0 :(得分:2)

试试这个:

final Collection<Integer> coll = Arrays.asList(8, 7, 5, 3, 6, 7, 12, 4);