How would I go about printing an array that holds a string that is in another class using println? An example of what I mean is:
public class questions{
public void QuestionDatabase(){
String[] QuestionArray;
QuestionArray = new String[2];
QuestionArray[0] = ("What is a dog?");
QuestionArray[1] = ("How many types of dogs are there?");
}
}
In this other class, I want to grab a question from there like so:
public class quiz{
public static void main (String[] args){
//Here is where I want to grab QuestionArray[0] and print to the screen.
System.out.println("");
}
}
QuestionArrayis a local variable that belongs to theQuestionDatabasemethod. When you call the method, it sets up the array, but when the method is done, the array disappears, along with all the work you did to set it up. The answers explain how to fix this.toString()on an array and get garbage output like[I@3343c8b3. Voting to reopen.