Skip to content

Instantly share code, notes, and snippets.

@RashidJorvee
Last active January 5, 2019 15:30
Show Gist options
  • Save RashidJorvee/5f4910326243ec2ea32d274803a83c92 to your computer and use it in GitHub Desktop.
Save RashidJorvee/5f4910326243ec2ea32d274803a83c92 to your computer and use it in GitHub Desktop.
Return list of objects from a method in Java
package rashid.jorvee;
import java.util.Arrays;
import java.util.List;
public class ReturnMultipleValueFromMethod {
public static void main(String[] args) {
List<Object> list=getQuestionAndViewType("M", "Survey");
System.out.println(list);
/* if you want to fetch a single value from list then use get() method with index number.*/
System.out.println(list.get(0));
}
public static List<Object> getQuestionAndViewType(String questionTypeEpsilon, String format){
String questionType="";
String viewType="";
if(format.equals("Survey") && questionTypeEpsilon.equals("M")) {
questionType = "multipleChoiceQuestion";
viewType = "question-answer-short-text";
}
else if(format.equals("Survey") && questionTypeEpsilon.equals("S")) {
questionType = "singleChoiceQuestion";
viewType = "question-answer-long-text";
}
else if(format.equals("Quiz") && questionTypeEpsilon.equals("S")) {
questionType = "singleChoiceQuestionInteractive";
viewType = "question-answer-long-text";
}
else if(format.equals("Quiz") && questionTypeEpsilon.equals("M")) {
questionType = "multipleChoiceQuestionInteractive";
viewType = "question-answer-short-text";
}
return Arrays.asList(questionType,viewType);
}
}
@RashidJorvee
Copy link
Author

RashidJorvee commented Jan 5, 2019

Output:

[multipleChoiceQuestion, question-answer-short-text]
multipleChoiceQuestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment