style question: length vs. size

H

Harald Kirsch

Vector has size().
Collection has size().
List has size().

StringBuffer has length().
String has length().
Arrays have length (the non-parentheses are not at issue here).

I am not sure if I see a consistent theme here. Is there
a theme? If I write a class to contain indexable elements,
along which guideline can I choose between length()
and size()?

Harald.
 
J

Jacob

Harald said:
Vector has size().
Collection has size().
List has size().

StringBuffer has length().
String has length().
Arrays have length (the non-parentheses are not at issue here).

I am not sure if I see a consistent theme here. Is there
a theme? If I write a class to contain indexable elements,
along which guideline can I choose between length()
and size()?

Use length() where the direction/order
of the elements has significance,
size() otherwise.

Of the above, only Collection qualify to
use size(). Vector and List use size()
because they inherit from Collection.
In my opinion Vector and List should
implement length() as a convenience
front-end to size().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top