Click here to Skip to main content
15,994,794 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
Java
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.
Java
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:
Java
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.

Java
Arrays mergevariables = ArrayUtils.addAll(Variable1,Variable2);
Collections.addAll(Variable1,Variable2);
Posted
Updated 20-Dec-15 16:39pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Dec-15 19:30pm    
There is no such arithmetic operation as "combine". You need to explain what you have to achieve and why.
—SA
Member 12219354 20-Dec-15 22:41pm    
I want to merge the two variables into one big variable which means I don't want to do any arithmetic operations.
Sergey Alexandrovich Kryukov 20-Dec-15 22:47pm    
You need to define what this "merge" means.
I also have no idea what kind of fantasy may come to the idea of "big variable".
—SA

1 solution

I already gave you a suggestion in the Java forum; please do not repost.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900