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 does java se mean?

1048


What does provide mean construction?

1105


What is Java Shutdown Hook?

1204


What do you mean by collectors in java 8?

935


Who is the owner of java?

1005


How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?

1014


What do you mean by inner class in java? Explain

1070


What are the different approaches to implement a function to generate a random number?

1061


Explain where variables are created in memory?

1014


What is namespace in java?

1015


What is the difference between synchronized and synchronized block?

1068


What is autoboxing in java?

1067


What is a text string?

1089


What is linkedlist in java?

1006


we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.

2034