Get uncommon elements from two list - KOTLIN : <p>I have two list of same model class (STUDENT), sample student object structure is given below, </p>

<pre><code>{
    "_id": "5a66d78690429a1d897a91ed",
        "division": "G",
        "standard": "X",
        "section": "Secondary",
        "lastName": "Sawant",
        "middleName": "Sandeep",
        "firstName": "Shraddha",
        "pin": 12345,
        "isEditable": true,
        "isTracked": 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>
