0 votes
1 view
in Java by (1.3k points)

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.

1 Answer

0 votes
by (13.2k points)

There is no such function or method in java, but there is a property which is useful in finding the length of array which is array.length

public class JavaArrayLengthExample

{

  public static void main(String[] args) {

      String[] intellipaat = {"java", "big data", "hadoop"};

      int arrayLength = intellipaat.length;

      System.out.format("The Java array length is %d", arrayLength);

  }

}

Output would be -

The Java array length is 3

...