title: Find Employees with same salary using Java 8 Streams
body: <p>Suppose we have a list of Employee objects { id, name, salary} . <strong>How to find the employees having the same salary?</strong>  using Java 8 Stream API ..</p>
  <p><strong>What I tried:-</strong>
  I guess this is indirect way of asking how to list employees &quot;based on&quot; salary, In that case we can <code>groupBy</code> Salary.  But that will display all salary and the list of employees with that salary .</p>
  <p><strong>Question:</strong> How to list only employees with same salary from this big map?</p>
  <p><strong>Solution I tried ::</strong></p>
  <pre><code>List&lt;Employee&gt; employees = new ArrayList&lt;&gt;();
  
          employees.add(new Employee(1, &quot;John&quot; , 1000));
          employees.add(new Employee(1, &quot;Peter&quot; , 2000));
          employees.add(new Employee(1, &quot;Ben&quot; , 3000));
          employees.add(new Employee(1, &quot;Steve&quot; , 2000));
          employees.add(new Employee(1, &quot;Parker&quot; , 1000));
  
  Map&lt;Integer, Set&lt;String&gt;&gt; map3 =  employees.stream()
                  .collect(Collectors.groupingBy
                          (Employee::getSalary, Collectors.mapping
                                  (Employee::getName, Collectors.toSet())));
  </code></pre>
  <p>OUTPUT</p>
  <p>map3 :: {2000=[Steve, Peter], 3000=[Ben], 1000=[Parker, John]}</p>
  <hr />
  <pre><code>public class Employee {
  
  public Employee(int id, String name, int salary) {
      this.id = id;
      this.name = name;
      this.salary = salary;
  }
  
  private int id;
  private String name;
  private int salary;
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public int getSalary() {
      return salary;
  }
  
  public void setSalary(int salary) {
      this.salary = salary;
  }
  </code></pre>
  <p>}</p>