title: How to filter the content of an ArrayList the right way?
body: <p>I was working on finding a better way to filter the content of an ArrayList</p>
  
  <p>For example, this program has a main ArrayList called "students" and then I made other sublistes from the content of this list (oldStudents,youngStudents,stupidStudents,smartStudents. The goal is to filter the ArrayList based on user choice of students (young,old, smart or stupids)</p>
  
  <pre><code>    ArrayList&lt;String&gt; students = new ArrayList&lt;String&gt;(); 
      ArrayList&lt;String&gt; smartStudents = new ArrayList&lt;String&gt;(); 
      ArrayList&lt;String&gt; stupidStudents = new ArrayList&lt;String&gt;(); 
      ArrayList&lt;String&gt; oldStudents = new ArrayList&lt;String&gt;(); 
      ArrayList&lt;String&gt; youngStudents = new ArrayList&lt;String&gt;(); 
  
  
      //adding all the students to students list 
      Collections.addAll(students, "Ram", "Mohan", "Sohan", "Rabi", "Shabbir","Jack", "Johnson", "Peter", "Despina", "Me");
      //adding young students to youngStudents list 
      Collections.addAll(youngStudents, "Ram", "Mohan", "Sohan", "Rabi", "Shabbir");
      //adding smart students to oldStudents list 
      Collections.addAll(oldStudents, "Jack", "Johnson", "Peter", "Despina", "Me");
      //adding smart students to smartStudents list 
      Collections.addAll(smartStudents, "Sohan", "Rabi", "Peter", "Despina");
      //adding smart students to stupidStudents list 
      Collections.addAll(stupidStudents, "Ram", "Mohan", "Shabbir","Jack", "Johnson", "Me");
  
      Scanner input = new Scanner(System.in);
      String uInput = "";
  
  
  
      System.out.print("This is a students search engine, write 'young' for younger students and 'old' for older ones ");
      uInput = input.nextLine();
  
      if(uInput.equals("young")) {
  
          students.removeAll(oldStudents); 
  
      } else if (uInput.equals("old")) {
  
          students.removeAll(youngStudents);
  
      }
  
  
      System.out.print("now write 'Smart' for smarter students and 'Stupid' for less smart students ");
      uInput = input.nextLine();
  
    if(uInput.equals("smart")) {
  
          students.removeAll(stupidStudents); 
  
      } else if (uInput.equals("Stupid")) {
  
          students.removeAll(smartStudents);
  
      }
  
  
    System.out.println(students);
  </code></pre>
  
  <p>It is working but I believe there is a better way to achieve this</p>