All array objects have one built-in public variable to determine the length of an array.

Syntax:

arrayName.length

double[] studentAvgs = new double[5]; //declare & allocate an array object
String[] strings = new String[10];
Student[] students = new Student[3];

System.out.println(studentAvgs.length); //This will print 5
System.out.println(strings.length); //This will print 10
System.out.println(students.length); //This will print 3

//2D array
double[][] numbers = new double[3][5];
System.out.println(numbers.length); //This will print 3

Leave a Comment