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 happens if a constructor is declared private?

1071


Explain the difference between comparator and comparable in java?

1022


Explain about the main() method in java?

1170


What environment variables do I need to set on my machine in order to be able to run java programs?

1057


What does snprintf return?

1052


Hi i am creating desktop application in that i want calling to mobile number. i have java telephone api (JTAPI) but i dont understand how it configure & use plese help me

1890


Can an anonymous class be declared as implementing an interface and extending a class in java programming?

1358


What is final access modifier in java?

1207


What is parsing and its types?

1178


Why can't you declare a class as protected?

1203


If we don’t want some of the fields not to serialize how to do that?

1062


How many bits are in a sentence?

1256


What is OOP's Terms with explanation?

1238


What is a method vs function?

1093


What is dynamic binding(late binding)?

1084