Back
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.
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); }}
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
31k questions
32.8k answers
501 comments
693 users