title: Selecting objects from an ArrayList based on value of certain fields
body: <p>I have a Course class, which has fields of various types, with their respective getters and setters, such as:</p>
  
  <pre><code>float percentage
  char courseLevel
  String courseName
  boolean takingNow
  </code></pre>
  
  <p>I then have an ArrayList of course objects and a method:</p>
  
  <pre><code>public &lt;T&gt; ArrayList&lt;Course&gt; getCourses(int parameterId, T value) {
      ArrayList&lt;Course&gt; res = new ArrayList&lt;Course&gt;();
      switch(parameterId) {
          case COURSE_NAME:
              for(Course c: courseList) {
                  if(c.getCourseName().equals(value) {
                      res.add(c)
                  }
              }
              break;
          ....
          //rest of the cases
          ....
      }
      return res
  }
  </code></pre>
  
  <p>the method then goes through the ArrayList of courses and compares a certain field based on the parameterId and if the course field equals the passed value it adds it to the to be returned arraylist.</p>
  
  <p>Is there a better way to do this than using generics in this way, which I feel is a very poor coding practice.</p>