I am trying to remove duplicates from an ArrayList in Kotlin. First of all I am getting a sortedNews from somewhere else and then I am adding it to the list called newsItems and then I am trying to remove the duplicates but the duplicates are still there. What am I doing wrong here
sortedNewsItems = nsItems!!.sortedWith(compareByDescending({it!!.timeStamp}))
newsItems?.addAll(sortedNewsItems!!)
newsItems?.distinct()
Log.e("first item name ",sortedNewsItems?.get(0)?.title)
recyclerView.adapter.notifyDataSetChanged()
newsItems?.distinct()returns new instance of collection.