title: How to convert a list into a set(avoid duplication) in Java 8?
body: <p>Here is the situation:
  We have a Student object which contains courseId as one of its fields.
  I want to return true if there is any student with course in history.</p>
  
  <pre><code>List&lt;Student&gt; students = new ArrayList();
  students.stream.anyMap(s -&gt; getFromDataBase(s.getCourseId()).name == "History");
  </code></pre>
  
  <p>Now, there is an optimization to prevent DB calls. Since many students can have the same courseId, it makes sense to filter out redundant courseId.</p>
  
  <p>Eg:</p>
  
  <pre><code>List&lt;Student&gt; students = new ArrayList();
  Set&lt;Id&gt; course = new HashSet&lt;&gt;();
  for (Student s : students) {
      course.add(s.getCourseId());  
  }
  
  course.stream.anyMap(s -&gt; getFromDataBase(s.getCourseId()).name == "History");
  </code></pre>
  
  <p>Now is there some way in Java-8, which I can use so that I don't need to do the following stuff:</p>
  
  <pre><code>  Set&lt;Id&gt; course = new HashSet&lt;&gt;();
      for (Student s : students) {
          course.add(s.getCourseId());  
      }
  </code></pre>