-2
I have the class Vetor which will have a method to start an array with random numbers:
public class Vetor{
private int tamanho;
private int[] vetor;
public Vetor(int tamanho) {
this.tamanho = tamanho;
this.vetor = vetor;
}
public void iniciaVetor() {
for (int i = 0; i < tamanho; i++) {
this.vetor[i] = (int) Math.random();
}
}
}
Now I got the class Arraylist which will have a method to hold a array vector:
public class Arraylist{
private int tamanho;
private ArrayList<Vetor> arraylist;
public Arraylist(int tamanho) {
this.tamanho = tamanho;
this.arraylist = new ArrayList<>();
}
public void iniciaArray(int tamanho_vetor) {
Vetor v;
for (int i = 0; i < tamanho_vetor; i++) {
v = new Vetor(tamanho_vetor);
v.iniciaVetor();
arraylist.add(v);
}
}
}
Finally, I have the class selects which has a method that will randomly select an index (an array from the list of vectors) and will populate that vector in the list temp. It will end by the temp be the same size as arraylist.
public class Selecao{
public ArrayList<Vetor> seleciona(ArrayList<Vetor> arraylist, tamanho_vetor) {
ArrayList temp = new ArrayList<>();
while (arraylist.size() != temp.size()) {
int numero_aleatorio = (int) Math.random();
//cromo adicionar o vetor da posição "numero_aleatorio" no arraylist temp
}
}
}
Create a
ArrayListbased on anotherArrayListis simple:List<AlgumaCoisa> a = ...; List<AlgumaCoisa> b = new ArrayList<>(a);- however, this is what the title of your question asks. What the content of your question asks for, it seemed to me very confusing. I recommend you describe verbatim what you are trying to do instead of already going to code.– Victor Stafusa