title: Java 8 : Filter 2 different JSON arrays according to certain fields
body: <p>This may be silly but I couldn't figure it out, I have 2 different schema JSON arrays.</p>
  
  <p><strong>JSON array A</strong></p>
  
  <pre><code>[
    {
       "name": "Robin",
       "uid": 1234   
    },  
    {
       "name": "Tom",
       "uid": 8768   
    },   
    {
       "name": "Eddy",
       "uid": 4534   
    }
  ]
  </code></pre>
  
  <p><strong>JSON array B</strong></p>
  
  <pre><code>[
    {
       "group": "Reign",
       "admin": 8768   
    },  
    {
       "group": "Hounds",
       "admin": 1234   
    },   
    {
       "group": "Dukes",
       "admin": 5996   
    }
  ]
  </code></pre>
  
  <p>Essentially the values of <strong>uid</strong> in JSON array A and <strong>admin</strong> field in JSON array B are same. The lists are very large so iteration is very expensive.</p>
  
  <p>My task is to get the elements of Array A matches with elements of Array B according to these 2 fields (uid &amp; admin). Also need to collect  excess elements of Array A and excess elements of Array B.</p>
  
  <p>What I have done so far</p>
  
  <pre><code>List&lt;JsonObject&gt; listOutput = jsonDataAList.stream()
                  .filter(e -&gt; jsonDataBList.stream()
                          .map(JsonDataA::getUid)
                          .anyMatch(admin -&gt; admin.equals(e.getAdmin())))
                  .collect(Collectors.toList());
  </code></pre>
  
  <p>Down voters please find time for any explanation</p>
  
  <p>Thank in advance. </p>