validate if there is a duplicate user using the stream distinct function in java 11

Viewed 21

I have a task list, where each task has a user list, and I need to validate if there is a duplicate user in any of the tasks in the user list.

Below is my object that I would like to validate:

{
  "tasks": [
    {
      "id": 1,
      "users": [
        {
          "username": "username1" 
        }
      ]
    },
    {
      "id": 2,
      "users": [
        {
          "username": "username1"
        },
        {
          "username": "username2"
        }
      ]
    }
  ]
}

I don't have a code that meets this solution, I need a boolean value of true or false if there is a duplicate user in my task list.

How can I do this using Java 11?

0 Answers
Related