title: Multiple Searches in a single text File
body: <p>So far I have made a program that can search for a single string in a text file. It does give the indexes of the string I searched for. However, how can I search for multiple string in a single text file?</p>
  
  <p>So far if I input "Alice" using the Scanner my output would be:</p>
  
  <pre><code>Got a match at line 17
  
  Got a match at line 19
  
  Got a match at line 20
  
  Got a match at line 21
  </code></pre>
  
  <p>However if it is possible, how can I search in my scanner for, Alice, John, Steven as my input and my output to be like:</p>
  
  <pre><code>Got a match for Alice at line 17
  
  Got a match at John at line 19
  
  Got a match at Steven at line 20
  
  Got a match at Steven at line 21
  </code></pre>
  
  <p>.</p>
  
  <pre><code>public static void main(String[]args) throws IOException{
  
      int nnames;
      String[] names;
      String stringSearch = null;
  
      Scanner scan = new Scanner(System.in);
      //for(int i=1;i&lt;=3;i++){
      stringSearch = scan.nextLine();
  
      ArrayList&lt;String&gt; words = new ArrayList&lt;String&gt;();
      BufferedReader reader = new BufferedReader(new FileReader("File1.txt"));
  
  
      String line;
  
      while ((line = reader.readLine()) != null) {                
          words.add(line);
      }reader.close();
  
  
      Collections.sort(words);
       System.out.println("ArrayList elements after sorting in ascending order : ");
       System.out.println("");
          for(int i=0; i&lt;words.size(); i++)
            System.out.println(words.get(i));
  
  
      for(String sLine : words) 
      {
          if (sLine.contains(stringSearch)) 
          {
              int index = words.indexOf(sLine);
              System.out.println("");
              System.out.println("Got a match at line " + index);
  
          }
       }
  
  
  
      System.out.println(words.size());
      }
  </code></pre>