Java String array: is there a size of method?

phill picture phill · May 28, 2009 · Viewed 871.5k times · Source

I come from a php background and in php, there is an array_size() function which tells you how many elements in the array are used.

Is there a similar method for a String[] array? Thanks.

Answer

Kris picture Kris · May 28, 2009

Yes, .length (property-like, not a method):

String[] array = new String[10];
int size = array.length;