Array length

17 January 2012 By Nithya Vasudevan 431 views No Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×

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

Tags: , ,