What is the difference between Length and length() in Java

1
238
views
Java Guide length vs. length( )
Java Guide length vs. length( )

Java Length and Length( )

What is the difference between Java Length and Length()?

In this post i am going to show you how Java length and length() work by simple example

Definition of length –  It is final variable applicable only for array.

It represent the size of array.

How to use length and how it is working by simple Java Length and Length( ) program

Java length and length()
Java length and length(), Core Java Guide in Hindi, Core Java Tutorials

Java length and length( ), Core Java Guide in Hindi, Core Java Tutorials

You can practice Java length and length( ) Program into your computer also.

    package Core;

public class demo_Length {

public static void main(String args[])

{

                     int[] g = new int[5];

                     System.out.println(g.length);

                     System.out.println(“this is a demo of length “);

                        }

                }

Definition  of length() method –  it is final method applicable only for String objects.

It represent number of characters present in String.

How to use length and how it is working by simple Java Length and Length( ) program

Java length and length()
Java length and length()

You can practice Java Length and Length() Program into your computer also.

package Core;

public class Demo_length_method {

              public static void main(String args[])

              {

                     String g = “Priyanshi”;

                     System.out.println(g.length());

                     System.out.println(“this is a demo of length() method “);

              }

}

In multidimensional arrays length variable represents only base size but not total size.

Int[] []  a = new int[5][3];

System.out.println(a.length()) ;

Remember :- length is  variable is only applicable for array.

And length() is  method which is applicable only for String objects.

Hope you like my post

What is the difference between Java length and length()

you would like to checkout- Java Arrays in Hindi

LEAVE A REPLY

Please enter your comment!
Please enter your name here