How to turn variables into one array?

Home » Programming & Design » How to turn variables into one array?
Programming & Design No Comments

if i have something like Animal a1 = new Animal(), a2 = new Animal();

how would i condense those into a single array?

Best Answer:

Jessica: Animal[] AnimalArray =new Animal[2];
AnimalArray[0] = a1;
AnimalArray[1] = a2;
….

Assuming you wan t to be able to edit it from a1 or from AnimalArray[0]

Other answer:

Jessica:
If you have just two Animal objects, then a single statement works in Java:

Animal[] a = {new Animal(), new Animal()};

roger:
Animal animals[3];
animal[0]=new animal();
XRCO:
Assuming you're using Java,
ArrayList<Animal> animalArray = new ArrayList<Animal>();
animalArray.add(a1);
animalArray.add(a2);
.
.
.
Divinotech:
In which programming language do you want to turn variables into one array is in it java or php.
i am telling you in php first if you need in java then ping me .
$countries = array(
"af" => "Afghanistan",
"ax" => "Ă…land Islands",
"al" => "Albania",
"dz" => "Algeria"
);

and some variables:

$as = "American Samoa";
$ad = "Andorra";

LEAVE A COMMENT