AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

array

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
luca
Guest





PostPosted: Thu Nov 25, 2004 7:41 am    Post subject: array Reply with quote



Come faccio a cancellare un'elemento di un array?

Grazie
Luca



Back to top
AlterX
Guest





PostPosted: Thu Nov 25, 2004 9:27 am    Post subject: Re: array Reply with quote



"luca" <lucaudine (AT) hotmail (DOT) com> ha scritto nel messaggio
news:co49je$b84$1 (AT) carabinieri (DOT) cs.interbusiness.it...
Quote:
Come faccio a cancellare un'elemento di un array?
dipende...se è un array di tipi primitivi (es: int, double...) non puoi,

ma potresti settare il valore a -1 ad esempio per indicare come cancellato.
Se si tratta di un array di oggetti, essendo questi dei riferimenti agli
oggetti stessi,
puoi usare:

String[] pippo = new String[20];
....
pippo[4] = null; // invoca il garbage collection

Ciao



Back to top
Vincent Vega
Guest





PostPosted: Thu Nov 25, 2004 1:34 pm    Post subject: Re: array Reply with quote



luca wrote:

Quote:
Come faccio a cancellare un'elemento di un array?

java.util.List tmpList;

tmpList = java.util.Arrays.asList(array);
tmpList.remove(index);
array = tmpList.toArray();

Il che ti fa riflettere sul fatto che è molto meglio usare una
collection di un array.


Back to top
luca
Guest





PostPosted: Fri Nov 26, 2004 8:15 am    Post subject: Re: array Reply with quote

Quote:
java.util.List tmpList;

tmpList = java.util.Arrays.asList(array);
tmpList.remove(index);
array = tmpList.toArray();

mi da questo errore:

"Utente.java": Error #: 354 : incompatible types; found: java.lang.Object[],
required: Servizi.ICI.anonimo.Immobile[] at line 103, column 37

perche?


Quote:
Il che ti fa riflettere sul fatto che è molto meglio usare una
collection di un array.
Tu hai ragione è meglio usare una collection ma sto modificando un sito

fatto da altri.



Back to top
luca
Guest





PostPosted: Fri Nov 26, 2004 10:57 am    Post subject: Re: array Reply with quote

Quote:
java.util.List tmpList;

tmpList = java.util.Arrays.asList(array);
tmpList.remove(index);
array = tmpList.toArray();

mi da questo errore:
"Utente.java": Error #: 354 : incompatible types; found:
java.lang.Object[],
required: Servizi.ICI.anonimo.Immobile[] at line 103, column 37

perche?

mi da anche

UnsupportedOperationException

perche?



Back to top
Vincent Vega
Guest





PostPosted: Fri Nov 26, 2004 11:21 am    Post subject: Re: array Reply with quote

luca wrote:
Quote:
java.util.List tmpList;

tmpList = java.util.Arrays.asList(array);
tmpList.remove(index);
array = tmpList.toArray();


mi da questo errore:
"Utente.java": Error #: 354 : incompatible types; found: java.lang.Object[],
required: Servizi.ICI.anonimo.Immobile[] at line 103, column 37

perche?

Perchè manca il cast.
Volevo lanciarti l'idea. Per una modica cifra posso impegnarmi a
scrivere esempi copia&incollabili ;-)




Back to top
luca
Guest





PostPosted: Fri Nov 26, 2004 11:57 am    Post subject: Re: array Reply with quote

Quote:
Perchè manca il cast.
Volevo lanciarti l'idea. Per una modica cifra posso impegnarmi a
scrivere esempi copia&incollabili Wink

Cosi va:
java.util.List tmpList;
tmpList = java.util.Arrays.asList(vett_immobili);
tmpList.remove(item);
tmpList.toArray(vett_immobili);

ma mi da un err runtime del tipo UnsupportedOperationException sulla riga
remove perche'?

io ho questo array:
Immobile[] immobili= new Immobile[100];

dovrei cancellare un'elemento,



Back to top
luca
Guest





PostPosted: Fri Nov 26, 2004 11:57 am    Post subject: Re: array Reply with quote

Quote:
Perchè manca il cast.
Volevo lanciarti l'idea. Per una modica cifra posso impegnarmi a
scrivere esempi copia&incollabili Wink

Cosi va:
java.util.List tmpList;
tmpList = java.util.Arrays.asList(vett_immobili);
tmpList.remove(item);
tmpList.toArray(vett_immobili);

ma mi da un err runtime del tipo UnsupportedOperationException sulla riga
remove perche'?

io ho questo array:
Immobile[] immobili= new Immobile[100];

dovrei cancellare un'elemento,




Back to top
luca
Guest





PostPosted: Wed Dec 01, 2004 7:59 am    Post subject: Re: array Reply with quote

mi puoi auitare?

Cosi va:
java.util.List tmpList;
tmpList = java.util.Arrays.asList(vett_immobili);
tmpList.remove(item);
tmpList.toArray(vett_immobili);

ma mi da un err runtime del tipo UnsupportedOperationException sulla riga
remove perche'?

io ho questo array:
Immobile[] immobili= new Immobile[100];

dovrei cancellare un'elemento,



Back to top
Marco Sarti
Guest





PostPosted: Wed Dec 01, 2004 8:57 am    Post subject: Re: array Reply with quote

luca wrote:
Quote:
mi puoi auitare?

Cosi va:
java.util.List tmpList;
tmpList = java.util.Arrays.asList(vett_immobili);
tmpList.remove(item);
tmpList.toArray(vett_immobili);

ma mi da un err runtime del tipo UnsupportedOperationException sulla riga
remove perche'?

In questo modo:

tmpList = new ArrayList(java.util.Arrays.asList(vett_immobili));

La ragione per cui non funziona è che Arrays.asList restituisce una
implementazione di List che non supporta il metodo remove(),
probabilmente perchè "nasconde" solo l'array evitando altri overhead.
Chiaramente tu devi "manipolarlo" e questo overhead ti serve. Per questo
è sempre valido il consiglio di usare direttamente una collection e non
un array.


Back to top
luca
Guest





PostPosted: Wed Dec 01, 2004 1:20 pm    Post subject: Re: array Reply with quote

Quote:
La ragione per cui non funziona è che Arrays.asList restituisce una

Grazie della cortesia, provero



Back to top
luca
Guest





PostPosted: Mon Dec 06, 2004 9:58 am    Post subject: Re: array Reply with quote

Quote:
java.util.List tmpList;
tmpList = java.util.Arrays.asList(vett_immobili);
tmpList.remove(item);
tmpList.toArray(vett_immobili);

In questo modo:

tmpList = new ArrayList(java.util.Arrays.asList(vett_immobili));

ho provato la tua soluzione ma mi da lo stesso errore:
UnsupportedOperationException

non so che fare

Grazie



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.