paranthesis use

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyotshna
    New Member
    • May 2011
    • 1

    paranthesis use

    Well ! I have a confusion.When we find length of an array we just use a.length; but to find length of an string we use S.length();.Why paranthesis are not used in case of array,however to call any method we use paranthesis?
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Because in case of array, length is not a method. it's a data member. Just made that way. They could have created a method for Array(), but they didn't. they probably have a good reason? I don't know.


    Dan

    Comment

    • William
      New Member
      • Jun 2011
      • 2

      #3
      arrays are static, fixed length you have to declare the length first. Therefore you can easily get the .length of an array (primitive). Where as of strings you need to count the char with in the string class(think blob) to get the count or length() (method) of a string.

      don't confuse the ArrayList() with standard Array[]; they are similar but ArrayList() is a class and Array[] is more primitive.

      hope this helps.

      Comment

      Working...