Since you want to preserve the order of responses, you probably want to use a List.
Then you just need to decide what kind of list to make. Since you have two items that are closely related - the subject (a String) and condition - I would probably create a custom class:
import java.util.Map;
public class QuestionInfo {
private String question;
private Map<String, String> variables;
public QuestionInfo(String question, Map<String, String> variables) {
this.question = question;
this.variables = variables;
}
public String question() {
return question;
}
public Map<String, String> vars() {
return variables;
}
}
Then you would create your list to store these like this, for example:
List<QuestionInfo> questionList = new ArrayList<QuestionInfo>();
There are other ways to store these strings (for example, you could concatenate them with a delimiter, or use a String[2]).. but this will probably be the easiest to read and understand later, in my opinion.
Here's an approximation of what the user would enter, and how you would use the questionList
+ QuestionInfo
to store the data:
[User] "how is the dog?" [Reply] "fine"
Map<String, String> varMap = new HashMap<String, String>();
varMap.put("subject", "dog");
varMap.put("condition", "fine");
questionList.add(new QuestionInfo("how is the dog?", varMap));
Now you can access this info by using:
questionList.get(0).question() // returns "how is the dog?"
or
questionList.get(0).vars().get("condition") // returns "fine"
Note that this is glossing over the code to actually gather the user input.
There are other possibilities.
You could pass in a String...
to the QuestionInfo
constructor and parse the variables/create the map there, for example.
You also may want to store the entire response as a String separate from the variables.
You may also want to create an enum for the keys, if you have a consistent set of keys you'll be populating.