Hi, I want to merge the two variables Variable1 and Variable2 together, but I couldn't merge them.
This is a separate class java file:
public class AnswerList {
private int mQuestion;
private int mAnswer;
private int mChoice1;
private int mChoice2;
private int mChoice3;
private int mChoice4;
public AnswerList(int question, int choice1, int choice2, int choice3, int choice4, int answer){
mQuestion = question;
mAnswer = answer;
mChoice1 = choice1;
mChoice2 = choice2;
mChoice3 = choice3;
mChoice4 = choice4;
}
I have to declared the two variables separately because I want to combine the two only if certain conditions are met. The issue I have is I can't get the combining to work.
private AnswerList[] Variable1 = new AnswerList[] {
new AnswerList(R.string.question1, R.string.answerone1,
R.string.answerone2, R.string.answerone3,
R.string.answerone4, 4),
new AnswerList(R.string.question2, R.string.answertwo1,
R.string.answertwo2, R.string.answertwo3, R.string.answertwo4, 2)};
private AnswerList[] Variable2 = new AnswerList[]{
new AnswerList(R.string.question5, R.string.answerfive1,
R.string.answerfive2, R.string.answerfive3,
R.string.answerfive4, 1)
};
I tried to used the following codes to merge them, but none of them worked. What am I doing wrong? Thanks!
I want to get the final result to be like this:
private AnswerList[] Variable1 = new AnswerList[] {
new AnswerList(R.string.question1, R.string.answerone1,
R.string.answerone2, R.string.answerone3,
R.string.answerone4, 4),
new AnswerList(R.string.question2, R.string.answertwo1,
R.string.answertwo2, R.string.answertwo3, R.string.answertwo4, 2),
new AnswerList(R.string.question5, R.string.answerfive1,
R.string.answerfive2, R.string.answerfive3,
R.string.answerfive4, 1)};
Note: I am a Java/Android beginner.
Arrays mergevariables = ArrayUtils.addAll(Variable1,Variable2);
Collections.addAll(Variable1,Variable2);