user1114
0
Q:

how to find length of array in java

let coolCars = ['ford', 'chevy'];
//to find length, use the array's built in method
let length = coolCars.length;
//length == 2.
16
/**
* An Example to get the Array Length is Java
*/
public class ArrayLengthJava {
public static void main(String[] args) {
String[] myArray = { "I", "Love", "Music" };
int arrayLength = myArray.length; //array length attribute
System.out.println("The length of the array is: " + arrayLength);
}
}
6
class Main {
  public static void main(String[] args) {
    // Creating an array called x.
    String[] x = new String[]{"This", "Should", "return", "4"};
    // "x.length" finds the length of the array "x".
    System.out.println(x.length);
    // returns 4
  }
}
1
Int[] array = {1,2,3};
int lengthOfArray = array.length; /** Finding the length of the array and storing it */
System.out.println(String.valueOf(lengthOfArray)); /** Should print out 3, String.value Of() is optional as printLn does this automatically. */
3

New to Communities?

Join the community