title: How to extract elements from ArrayList specifically?
body: <p>I am tasked to develop a program that prompts users to create their own questions and answers, which will be stored into the arrayList. After that, whenever the user types the same question, the program will automatically extract the answer. </p>
  
  <p>What I did so far: I manage to store the questions and answers into the arrayList, but I have no idea how to trigger the program to extract exact answer when the user asked the question that he had just created. Here are my codes : </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class CreateQns {
  
      public static void main(String[] args) {
          String reply;
          ArrayList qns = new ArrayList();
          ArrayList ans = new ArrayList();
          System.out.println("Type 0 to end.");
  
          do {
              Scanner input = new Scanner (System.in);
              System.out.println("&lt;==Enter your question here==&gt;");
              System.out.print("You: ");
              reply = input.nextLine();
              if(!reply.equals("0")) {
                  qns.add(reply);
                  System.out.println("Enter your answer ==&gt;");
                  System.out.print("You: ");
                  ans.add(input.nextLine());
              }
              else {
                  System.out.println("&lt;==End==&gt;");
              }
          }while(!reply.equals("0"));
      }
  
  }
  </code></pre>