Monday, 7 May 2012

What's the difference between length and length()?

length is the property of array

it tells the length of a given array

eg. int a[]=new int[5];

a.length will give 5;

length() is a methds defied in string libaray
it tell the length of given string;
String s="ram";
s.length() will give 3

String s[]={"one","two","three"};
s.length will be 3 as there are 3 elements in s(String type array)
s[2].length() will be 5 as the length of string at postion 2 is 5 i.e "three"

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...