Question: I have two different lists of objects I want to display all element of first except those which has a common name property. Is there any better approach to this problem?

What I have tried. It's still not working as this filter out only one element rest gets added.

```
private fun getNonCommonUsers(users: List<UserModel>, userlist: List<User>): List<User> {
    val nonCommonUsers = ArrayList<User>()
    if(userlist.isNotEmpty()) {
        for (user in Users) {
            for (userl in userlist) {
                if (userl.getUserName(getResourceProvider(requireContext())) != user.getDisplayName()) {
                    if(!nonCommonUsers.contains(userl))
                        nonCommonUsers.add(userl)
                }
            }
        }
    }
    return nonCommonUsers
}

```

Answer: 
If I understand your question correctly, you want to return a list of all users in `userlist: List<User>` where the username does not exist in `users: List<UserModel>`.

You can use the `filter`-method on `userList` for this operation. I am first getting all the relevant usernames from `users`, by using the `map` function. Then I am creating a new list of users from `userlist` by filtering out all users with a username that exists in the `usernames` set. Like this:

```
private fun getNonCommonUsers(users: List<UserModel>, userlist: List<User>): List<User> {
    val resourceProvider = getResourceProvider(requireContext())
    val usernames = users.map { it.getDisplayName() }.toSet()
    return userList.filter { it.getUserName(resourceProvider) !in usernames }
}

```
if I have understood what you want to do maybe you can try:

```

private fun nonCommonUsers(users: List<UserModel>, userlist: List<User>): List<User> =
    users.map { User (userName = mapDisplayName(it.displayName))}.minus(userlist)

```