Sto creando un ArrayList
e la sua dimensione è 40
Initilize un ArrayList con zeri
ArrayList<Integer> myList= new ArrayList<>(40);
Come posso inizializzare myList
con zeri 0
? Ho provato questo
for(int i=0; i<40; i++){
myList.set(i, 0);
}
ma ottengo
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Si noti che 'Arrays.asList (new int [40])' restituisce 'List' quindi l'istruzione sopra riportata fornirà un errore in fase di compilazione. –