How to create variable dynamically?

2

I would like to create a variable for each iteration of a for. Example:

for(u=0;u<tamanho;u++)
{
  int variavel[u] = "valor"
}

Is it possible?

UPDATE

This is the actual code.

  SearchConstraint c1 = factory.createConstraint("metadata#version", f1, f1, ConstraintType.MUST);
  SearchConstraint c2 = factory.createConstraint("regiao_codigo", "1", "1", ConstraintType.MUST);
  SearchConstraint[] constraints = new SearchConstraint[2];
  constraints[0] = c1;
  constraints[1] = c2;
  dataset = factory.getDataset("ibv", null, constraints, null);

See that you have two variables c1 and c2. I need to create them dynamically.

    
asked by anonymous 05.10.2015 / 20:55

1 answer

6

For this snippet of your code:

constraints[0] = c1;
constraints[1] = c2;

I realize that you are putting variables c1 and c2 into a vector anyway. So, using your code example, why not create those variables already inside this vector?

for(u=0;u<tamanho;u++)
{
    constraints[u] = "valor"
}
    
05.10.2015 / 22:43