Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Length of an object array [duplicate]

Tags:

java

arrays

Possible Duplicate:
Java Arrays - length

How do you determine the length of an array that is not an String array or an integer array? It won't let me use .length(), but only .length?

Why and is there another way of determining this?

like image 719
BrobaFett44 Avatar asked Nov 26 '12 06:11

BrobaFett44


1 Answers

You can use getLength method from java.lang.reflect.Array, which uses reflection (so it'll be slow):

Object[] anArray = new Object[2];
int length = Array.getLength(anArray);
like image 196
vels4j Avatar answered Sep 19 '22 11:09

vels4j