Java Array Length
We can find the length of an array by using length variable.
1. length variable:-
length is a final variable applicable only for arrays.
length variable represents the size of an array.
example:
int [ ] x = new int [6];
System.out.println(x.length); o/p is 6 .
int [ ] x =new int [10];
System.out.println(x.length); o/p is 10 .
System.out.println(x.length());
But Do not Apply length( ) method here.Because length( ) is applicable for String.
2.length ( ) method:-
length( ) is a final method appicable for String Objects/
length( ) return the numbers of character present in the String.
example:
String s="javabychetan";
System.out.println(s.length()); o/p is 12
System.out.println(s.length);
Compile-Time Error: cannot find symbol
Symbol: variable length
location: class java.lang.String
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home