-1

I have String Vector of Vectors in Java called data. I can access this vector elements:

(Vector) data.get(i)).get(j); 

How can i get count of inner vectors (i) and element count in each inner vector (j).

Karloss
  • 817
  • 3
  • 9
  • 27

2 Answers2

2

Use Vector.size() to get collection size. While this would solve your immediate problem:

int innerCount = ((Vector)data).size();
for (Object v: data) {
   int elementCount = ((Vector)v).size();
   ...
}

would suggest to use generics here to avoid casting:

int innerCount = data.size();
for (Vector v: data) {
   int elementCount = v.size();
   ...
}

Also ArrayLists are typically used now since the introduction of the Collections API in Java 2. See ArrayLists vs Vectors

Community
  • 1
  • 1
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Hello @Reimeus !! I have a question .. I have multidimensional Vector, on index[0] I have an array "[256, 222, 11813, 61, 61, 11813]" .. so how can we get index[0][2], without making loop ? – Google User Feb 06 '14 at 09:37
1

Number of inner vectors:

((Vector)data).size();

Number of elements of each inner vector:

for(Vector v : (Vector)data) {
    int nrElemsInCurrentInner = v.size();
}
halex
  • 16,253
  • 5
  • 58
  • 67