A simple java program to find the length of the array and string a single program. Using this program we can calculate array and string in the array in java. The array length in Java refers to the maximum number of elements that an array can hold. The length of an array cannot be determined using any predefined method. The array attribute length in Java can be used to determine the array length.
public class Main
public static void main(String args)
int array = new int;
System.out.println("The size of the array is " + array.length);
String str = "Inlarn.com";
System.out.println("The size of the String is "+ str.length());
The size of the array is 4
The size of the String is 10
What is length() in java
The length() method of the String class is a static method. The length() method returns the length of a string object or the number of characters it contains. This function is used by the String class because the length of a string can be changed using various operations on an object.