title: Unable to get desired output in "Predicate" "and" of Java
body: <p>I have the following class Person -</p>
  <p><code>Person.java</code> -</p>
  <pre><code>public class Person {
      private int id;
      private String department;
      private double salary;
  
      public Person(int id, String department, double salary) {
          this.id = id;
          this.department = department;
          this.salary = salary;
      }
  
      public String getDepartment() {
          return department;
      }
  
      public double getSalary() {
          return salary;
      }
  
      @Override
      public String toString() {
          return &quot;Person{&quot; +
                  &quot;id=&quot; + id +
                  &quot;, department='&quot; + department + '\'' +
                  &quot;, salary=&quot; + salary +
                  '}';
      }
  }
  
  </code></pre>
  <p>It has the fields -</p>
  <p><code>id</code>, <code>department</code>, <code>salary</code></p>
  <p>Now I have first predicate -</p>
  <pre><code>Predicate&lt;List&lt;Person&gt;&gt; hasSalaryOf40k = list -&gt; {
              boolean myReturn = false;
              Iterator&lt;Person&gt; iterator = list.iterator();
              while (iterator.hasNext()) {
                  Person person = iterator.next();
                  double salary = person.getSalary();
                  if (salary == 40000) {
                      myReturn = true;
                      break;
                  }
              }
              return myReturn;
          };
  </code></pre>
  <p>Here, I want to filter out those lists having persons with salary as 40K.</p>
  <p>Second predicate -</p>
  <pre><code>Predicate&lt;List&lt;Person&gt;&gt; isDeveloper = list -&gt; {
              boolean myReturn = false;
              Iterator&lt;Person&gt; iterator = list.iterator();
              while (iterator.hasNext()) {
                  Person person = iterator.next();
                  String department = person.getDepartment();
                  if (department.equals(&quot;Developer&quot;)) {
                      myReturn = true;
                      break;
                  }
              }
              return myReturn;
          };
  </code></pre>
  <p>Here, I want to filter out those lists having persons with department as 'developer'</p>
  <p>Third predicate -</p>
  <pre><code>Predicate&lt;List&lt;Person&gt;&gt; hasSalaryOf40kAndIsDeveloper = list -&gt;
                  hasSalaryOf40k.and(isDeveloper).test(list);
  </code></pre>
  <p>Here, I want to filter out those lists having persons with both salary as 40K and department as &quot;developer&quot;</p>
  <p>Now I have the following two lists -</p>
  <pre><code>List&lt;Person&gt; list1 = new ArrayList&lt;&gt;(List.of(
                  new Person(1, &quot;Developer&quot;, 35000),
                  new Person(2, &quot;Accountant&quot;, 40000),
                  new Person(3, &quot;Clerk&quot;, 20000),
                  new Person(4, &quot;Manager&quot;, 50000)
          ));
  
          List&lt;Person&gt; list2 = new ArrayList&lt;&gt;(List.of(
                  new Person(1, &quot;Developer&quot;, 40000),
                  new Person(2, &quot;Accountant&quot;, 35000),
                  new Person(3, &quot;Clerk&quot;, 22000),
                  new Person(4, &quot;Manager&quot;, 55000)
          ));
  </code></pre>
  <p>The <code>list1</code> does not match the desired criteria while <code>list2</code> matches the desired criteria.</p>
  <p>Now I call the predicate method test -</p>
  <pre><code>System.out.println(hasSalaryOf40kAndIsDeveloper.test(list1));
  System.out.println(hasSalaryOf40kAndIsDeveloper.test(list2));
  </code></pre>
  <p>Output -</p>
  <pre><code>true
  true
  </code></pre>
  <p>Desired output -</p>
  <pre><code>false
  true
  </code></pre>
  <p>Where am I going wrong and how to correct my code?</p>