Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is difference between length and length()?

Answer Posted / abel

length and length( )
A) length variable:
length is an instance variable of type array. Array is an object, just like string, Object, JFrame, etc. The array class has an instance variable called length, when you say arrayName.length, you are getting the length of an array.
int student[] = new int[5];
System.out.println(student.length); // prints 5

length() method:
It is a method defined in String class. It gives the number of characters present in the string.

String str = "hello";
System.out.println(str.length()); // prints 5

Notice that in the first example made the length variable public, it can be accessed anywhere. In the second example it is private and cannot be accessed directly, so we provide a method which allows us to view the length variable.

It is like comparing two strings with == and equals(). equals() is a method call which takes more time than executing == operator.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the purpose of the strictfp keyword?

1161


Can we have any code between try and catch blocks?

988


What is the access scope of protected access specifier?

998


What is the set interface in java programming?

1210


os is developed in c no java is more secured then c na why dont the os developed is developed using java

4228


What do you mean by local class?

1006


How do you clear a method in java?

1005


What is the difference between procedural and object-oriented programs?

973


List some oops concepts in java?

1034


what do you mean by classloader?

1090


When should you make a function static?

987


What is java jit compilers?

1010


Why declare Main() inside the class in java ?

1060


What happens if main method is not static?

998


When should you use arraylist and when should you use linkedlist?

927