What is the difference between element and component?

R

RC

In Vector class

there are methods:

boolean add(E o)
Appends the specified element to the end of this Vector.

void addElement(E o)
Adds the specified component to the end of this vector,
increasing its size by one.

E get(int index)
Returns the element at the specified position in this Vector.

E elementAt(int index)
Returns the component at the specified index.

What is element? what is component?
Please give the examples.

P.S. in ArrayList class, there are only

boolean add(E o)
E get(int index)

So in ArrayList class you can only add/get elements,
But you can't addElement(E o)/elementAt(int index)

Why?

Thanks Q very much in advance!
 
C

Chris Smith

RC said:
there are methods:

boolean add(E o)
void addElement(E o)
E get(int index)
E elementAt(int index)
What is element? what is component?

Element and component mean the same thing in this context. The reason
for the duplicates is that Vector existed before the List interface,
which it now implements. New methods had to be added to meet the
requirements of the List interface, but old methods had to be kept
around so that older code would still compile.

For modern code intended for Java 1.2 and above, it's best to use the
new methods, as described by the List interface.
P.S. in ArrayList class, there are only

boolean add(E o)
E get(int index)

That's because ArrayList was introduced as part of generics, so there's
no historical crud.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

What is element? what is component?
Please give the examples.

The person who wrote this erred. He properly should have said
"Object" in all cases. The things in a Vector or the members of a set
are often called elements. This is terminology from mathematical set
theory.

The word Component is a generic term for an AWT widget since all of
them derive from it. The author was probably used to thinking of
Vectors as containing Components for layout managers.

You could put in a nit picky bug report. See
http://mindprod.com/jgloss/bugs.html
 
T

Thomas Hawtin

Roedy said:
The word Component is a generic term for an AWT widget since all of
them derive from it. The author was probably used to thinking of
Vectors as containing Components for layout managers.

Component is the term used by the JLS to describe an array "element".

Tom Hawtin
 
T

Thomas Hawtin

Chris said:
For modern code intended for Java 1.2 and above, it's best to use the
new methods, as described by the List interface.

Unless you want the code to run under J2ME as well.

Tom Hawtin
 
E

Eric Sosman

Chris Smith wrote On 09/27/05 14:16,:
That's because ArrayList was introduced as part of generics, so there's
no historical crud.

ArrayList showed up in 1.2, well before generics. You
probably meant "as part of the Java Collections Framework."
 
C

Chris Smith

Eric Sosman said:
Chris Smith wrote On 09/27/05 14:16,:

ArrayList showed up in 1.2, well before generics. You
probably meant "as part of the Java Collections Framework."

s/generics/Collections/g

Sorry, my typo.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

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
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top