Loading...
Java

length Vs length() Method

length:
It is the applicable only for array. It represents the size of the array
Example:
int[] array=new int[5];
System.out.println(array.length);
Output:
5

In multidimensional array length represents only base size not a total size
Example:
int[][] arr=new int[5][3];
System.out.println(arr.length);
System.out.println(a[0].length);
Output:
5
3

length():
It is the method applied only for String objects. It represents the size of (number of characters in) the string.
Example:
String str=”Webnoid”;
System.out.println(str.length()):
Output:
7

Leave a Reply

Your email address will not be published. Required fields are marked *