This page topics close
  • 1) length

    It is a final variable applicable only for Arrays.

    It represent the size of an Array.

    Example)
    drag_handle
     
    //example of length
    class Example {
    
        public static void main(String[] args) {
            int a[] = {2, 3, 23, 5};
            int size = a.length; //using length property
            System.out.println("Size of array is = " + size);
        }
    }
    Output:
    Size of array is = 4
  • 1) length()

    It is a final method applicable only for String Object.

    It represent the number of character present in String.

    Example)
    drag_handle
     
    //example of length()
    class Example {
    
        public static void main(String[] args) {
            String str = "Java is powerful language ";
            int numberOfChar = str.length(); //using length method
            System.out.println("Number of characters  = " + numberOfChar);
        }
    }
    Output:
    Number of characters  = 26

What next?

The next topic is Anonymous Arrays in java

Share this page