0

i want to create a array of (vector of (arrays that size 2)) like

Vector<Integer[2]>[]

i tried

Vector<Integer[]>[] arr2 = new Vector[5];

for (int i=0; i<5; i++){
  arr2[i] = new Vector<Integer[]>();
}
int[] arr = {1,5};
arr2[0].add(arr);

but it have a error

The method add(Integer[]) in the type Vector<Integer[]> is not applicable for the arguments (int[])

is it possible convert int[] to Integer[] or create vector with int[] instead of Integer[]?

how can i create this??

dtd
  • 81
  • 7
  • `int` and `Integer` can autobox and un-box into one another, but `int[]` and `Integer[]` are two different object types, as they are array types. You can either make your `Vector` for `int[]`s or declare your `arr` as `Integer[]`. Inserting `int`s into either array type should work due to autoboxing. – Zircon Oct 13 '16 at 13:45
  • Why do you need this usage. Vector is considered as [absolute](http://stackoverflow.com/questions/1386275/why-is-java-vector-class-considered-obsolete-or-deprecated) – erencan Oct 13 '16 at 13:46

2 Answers2

0

Here is the correct way to declare/use it:

Vector<int[]> arr2 = new Vector<int[]>();//Correct declaration syntax

int[] arr = {1,5};
for (int i=0; i<5; i++){
     arr2.add(arr);
}

You can either do that with Integer, but not mix them:

Vector<Integer[]> arr2 = new Vector<Integer[]>();

Integer[] arr = {1,5};
for (int i=0; i<5; i++){
     arr2.add(arr);
}
Treycos
  • 7,373
  • 3
  • 24
  • 47
0

try this

 Integer[] arr = { 1, 5 };
arr2[0].add(arr);

I suggest to remain with Integer if you want to treat null values

Arctigor
  • 247
  • 2
  • 5