Here you can find the source of queryMenu(Scanner in, String msg, LinkedList
public static int queryMenu(Scanner in, String msg, LinkedList<String> options)
//package com.java2s; //License from project: Open Source License import java.util.LinkedList; import java.util.Scanner; public class Main { public static int queryMenu(Scanner in, String msg, LinkedList<String> options) { System.out.printf("%s\n", msg); // print out the message to stdout while (true) { int idx = 0; for (String option : options) { System.out.printf("\t%d. %s\n", idx, option); idx++;//www .j a va 2s . c o m } System.out.printf("Enter an option from the list above: "); String response = in.nextLine(); for (String opt : options) { if (response.equals(opt)) { return options.indexOf(response); } else { int result = Integer.parseInt(response); try { options.get(result); return result; } catch (IndexOutOfBoundsException e) { System.out.printf("No element exists at %d", result); } } } System.out.printf("Input did not match any option. Try again.\n"); } } public static int queryMenu(Scanner in, String msg) { System.out.printf("%s\n", msg); String response = in.nextLine(); return Integer.parseInt(response); } }