Discussione:
Differenza tra metodo add ed addElement della Classe Vector
(troppo vecchio per rispondere)
cutoff
2005-01-11 11:06:43 UTC
Permalink
Ciao a tutti,

mi dite cortesemente le differenze tra l'utilizzo del metodo :
boolean add(Object o)
" Appends the specified element to the end of this Vector "
e quello
void addElement(Object obj)
"Adds the specified component to the end of this vector, increasing its size
by one "
visto che in ogni caso vengono aggiunti degli oggetti al vettore?

Grazie


Nicola

--------------------------------
Inviato via http://arianna.libero.it/usenet/
fabrizio
2005-01-11 12:28:17 UTC
Permalink
Post by cutoff
Ciao a tutti,
boolean add(Object o)
" Appends the specified element to the end of this Vector "
e quello
void addElement(Object obj)
"Adds the specified component to the end of this vector, increasing its size
by one "
visto che in ogni caso vengono aggiunti degli oggetti al vettore?
La differenza è scritta nella doc API ed è.... nessuna.

"addElement

public void addElement(E obj)

Adds the specified component to the end of this vector, increasing
its size by one. The capacity of this vector is increased if its size
becomes greater than its capacity.

This method is identical in functionality to the add(Object) method
(which is part of the List interface).

Parameters:
obj - the component to be added.
See Also:
add(Object), List

"

ciao

Fabrizio
N. B.
2005-01-11 14:26:27 UTC
Permalink
"cutoff" <***@libero.it> ha scritto nel messaggio news:***@usenet.libero.it...
[cut]
Post by cutoff
Grazie
Nicola
--------------------------------
Inviato via http://arianna.libero.it/usenet/
Oltre al fatto che add restituisce un boolean e addElement no, suppongo che
addElement sia mantenuto per compatibilità con qualche versione precedente
di Java. Per il resto lo dice anche la documentazione: sono identici.

Ciao
Niko
Vincent Vega
2005-01-11 22:51:55 UTC
Permalink
Post by cutoff
boolean add(Object o)
" Appends the specified element to the end of this Vector "
e quello
void addElement(Object obj)
"Adds the specified component to the end of this vector, increasing its size
by one "
visto che in ogni caso vengono aggiunti degli oggetti al vettore?
add() è un implementazione dell'interfaccia List. addElement() no.
La classe Vector con java 2 è stata portata ad implementare
l'interfaccia List per rientrare nel Java Collection Framework e
addElement() è un "residuo" delle versioni precedenti.

Funzionalmente sono la stessa cosa. E' chiaro però che il metodo add() è
esposto dall'interfaccia List ed è quello che usi quando usi questa
interfaccia (e quindi non sai che è un Vector).

Loading...