4
I have a method that takes an unknown amount of parameters like an Array, thus:
public void enviarCampos(String funcao, String... campos) {
// Ação do método
}
To call this method do:
enviarCampos("CADASTRAR", "nome", "dataNascimento", "sexo", "rg", "cpf");
The problem is that I don’t know what these parameters will be, they will depend on various conditions, so I can’t put fixed. I put these parameters in a ArrayList
, so that I can manipulate the list of parameters, and I tried to make a cast to call the method but it did not work:
ArrayList<String> listaCampos = new ArrayList<>(Arrays.asList("nome", "dataNascimento", "sexo", "rg", "cpf"));
enviarCampos("CADASTRAR", (String[]) listaCampos.toArray());
Someone knows how to do?
Related: What mean the reticence in the parameters of a method?
– user28595
Because you can’t type the data into the method?
– novic