what is difference between length and length()?

Answers were Sorted based on User's Feedback



what is difference between length and length()? ..

Answer / malligontla

length is used for arrays and length() is used for strings

Is This Answer Correct ?    26 Yes 5 No

what is difference between length and length()? ..

Answer / dinesh

length is a variable wich is used in arrays for find out
the length.lenght() is function defined in Object class as
well as String class for find out the length of String

Is This Answer Correct ?    21 Yes 0 No

what is difference between length and length()? ..

Answer / shaik baji

length: It's a built-in property to determine the size of
any array.

lenght(): It's a method of java.lang.String class.
Syntax:
-------
public int length()

It returns the length of the string. The length is equal to
the number of 16-bit Unicode characters in the string.

Is This Answer Correct ?    6 Yes 0 No

what is difference between length and length()? ..

Answer / arun

length in array, is a property...
length() in Object is a method.

Is This Answer Correct ?    4 Yes 0 No

what is difference between length and length()? ..

Answer / rakesh

length is used as member of Object class such as String or
array as a member variable
and length() is a fuction which returns length of object
in characters

Is This Answer Correct ?    1 Yes 0 No

what is difference between length and length()? ..

Answer / manish

length is the variable for for calculating the length of primitive type variable and length() is the method object class for calculating the length of any object..

Is This Answer Correct ?    1 Yes 0 No

what is difference between length and length()? ..

Answer / murali.s

length is a property.it is used to fine array lenght
lenght()is a method.it is used to find string length

Is This Answer Correct ?    1 Yes 1 No

what is difference between length and length()? ..

Answer / 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

More Core Java Interview Questions

when System.out.println("") is executed what happens in the back ground?

2 Answers  


How do you reverse a list?

0 Answers  


Can we have multiple classes in a single file?

0 Answers  


What do you mean by an interface in java?

0 Answers  


Give an example of call be reference significance.

0 Answers   Agilent,






What is the main difference between java platform and other platforms?

0 Answers  


What do you mean by a JVM?

0 Answers   GE,


i need to know the site which compiles and run the java program completely in online... thank you for your reply in advance

2 Answers  


What is meant by method?

0 Answers  


What are uses of Hash Code?

2 Answers   Cognizant,


HOW TO PRINT A NO IN WORDS USING WHILE LOOP THE NO WILL BE PRINTED WHEN IT WILL BE IN THE RANGE BETWEEN 1 AND 3?

1 Answers  


Write a program to show whether a graph is a tree or not using adjacency matrix.

0 Answers   Amazon,


Categories