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
What does java se mean?
What does provide mean construction?
What is Java Shutdown Hook?
What do you mean by collectors in java 8?
Who is the owner of java?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
What do you mean by inner class in java? Explain
What are the different approaches to implement a function to generate a random number?
Explain where variables are created in memory?
What is namespace in java?
What is the difference between synchronized and synchronized block?
What is autoboxing in java?
What is a text string?
What is linkedlist in java?
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.