title: Get uncommon elements from two list - KOTLIN
body: <p>I have two list of same model class (STUDENT), sample student object structure is given below,</p>
  <pre><code>{
    &quot;_id&quot;: &quot;5a66d78690429a1d897a91ed&quot;,
    &quot;division&quot;: &quot;G&quot;,
    &quot;standard&quot;: &quot;X&quot;,
    &quot;section&quot;: &quot;Secondary&quot;,
    &quot;lastName&quot;: &quot;Sawant&quot;,
    &quot;middleName&quot;: &quot;Sandeep&quot;,
    &quot;firstName&quot;: &quot;Shraddha&quot;,
    &quot;pin&quot;: 12345,
    &quot;isEditable&quot;: true,
    &quot;isTracked&quot;: false
  }
  </code></pre>
  <p>One list have 3 objects and other 2. lets say, List A has 1, 2, 3 students and List B has 1, 2</p>
  <p>So my question is there any inbuilt functions to get the uncommon element <strong>by comparing just the id</strong>? If not how can i solve this issue.</p>
  <p>FYI, following are the two approaches i have made to solve, but failed miserably.</p>
  <p>Approach 1.</p>
  <pre><code>internal fun getDistinctStudents(studentsList: List&lt;Students&gt;, prefStudents: List&lt;Students&gt;): List&lt;Students&gt; {
      val consolidated = prefStudents.filter {
          prefStudents.any { students: Students -&gt; it._id == students._id }
      }
      return prefStudents.minus(consolidated)
  }
  </code></pre>
  <p>Approach 2.</p>
  <pre><code>internal fun getDistinctStudents(studentsList: List&lt;Students&gt;, prefStudents: List&lt;Students&gt;): List&lt;Students&gt; {
      val consolidatedStudents = studentsList + prefStudents
      val distinctStudents = consolidatedStudents.distinctBy{ it._id }
      return prefStudents.minus(distinctStudents)
  }
  </code></pre>
  <p>Any kind of help will be greatly appreciated.</p>
  <p>Thanks</p>