Salve.Ho un problema,non so come scorrere un SET?Come posso fare?
Inoltre può essere eseguito un cast ad un ArrayList?
Salve.Ho un problema,non so come scorrere un SET?Come posso fare?
Inoltre può essere eseguito un cast ad un ArrayList?
No, il cast non va di certo bene.Originariamente inviato da tcc
Salve.Ho un problema,non so come scorrere un SET?Come posso fare?
Inoltre può essere eseguito un cast ad un ArrayList?
Un Set può essere semplicemente "iterato" usando l'apposito iteratore, vedi iterator(). Se usi Java 5 puoi anche usare più facilmente il costrutto for-each.
Eventualmente puoi anche ottenere un array che contiene tutti i dati nel set ... ma dipende da cosa devi fare di preciso.
Andrea, andbin.dev – Senior Java developer – SCJP 5 (91%) • SCWCD 5 (94%)
java.util.function Interfaces Cheat Sheet — Java Versions Cheat Sheet
Devo prendere il primo elemento di un Set,devo usare iterator().next()?
Se sai che c'è almeno 1 elemento, sì è corretto (se non usi i generics, devi fare un cast al tuo tipo specifico).Originariamente inviato da tcc
Devo prendere il primo elemento di un Set,devo usare iterator().next()?
Riguardo all'ordine con cui si presentano gli elementi invece dipende dalla implementazione di Set che hai usato.
Andrea, andbin.dev – Senior Java developer – SCJP 5 (91%) • SCWCD 5 (94%)
java.util.function Interfaces Cheat Sheet — Java Versions Cheat Sheet