Back

Explore Courses Blog Tutorials Interview Questions
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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 29, 2019 in Java by Ritik (3.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...