Assuming that your String array is this and that you are initializing a ModeValue
object with it:
new String[] {
"cat", "dog", "rabbit", "horse", "bear", "fish", "bird", "snake"
}
Right now, it is declared anonymously. You have to declare it earlier with a name to access it using its name and index.
Ex:
String[] animals = new String[] {"cat", "dog", "rabbit", "horse", "bear", "fish", "bird", "snake"};
System.out.print(animals[0]); //cat
public ModeValue mode = new ModeValue("test_mode", "dog", animals, this);
Without more detail about ModeValue
, I'm not sure how to help with the switching or how to access the array within the mode
object. You might implement a get
method in ModeValue
to return the array, which will allow you to access it as normal.
Example of how you would declare a get method in the ModeValue class
public class ModeValue
{
private String[] animals;
public getAnimals()
{
return animals;
}
}
And get animals like in your main method like so:
String[] mainAnimals = mode.getAnimals();