0
I’m making a java application, and I used netbeans to build the screen. On this screen I have a button that generates random numbers and puts them inside an array, but I can’t change the size of it when it’s running.
What I did: I created a "tam" variable and assigned it to the vector
int vetor[] = new int[tam];
Then I created a button that updates the "tam" variable, defined in a field.
tam = Integer.parseInt(txtTamanho.getText());
But when the vector again Gero it continues with the same size.
Impossible, the size of an array is immutable. What you can do is create a new one with the larger size and repopulate, or use Collections.
– user28595
You won’t be looking for
ArrayList<Integer>
?– Isac
I’d put it on the button:
vetor = new double[tam]
– Magno
Do you put these numbers in the vector for what purpose? What are you going to use this vector for?
– Victor Stafusa
This vector stores the value of the products I have, the size of the vector indicates the number of products
– Magno