I wanted to know how to compare two values of a List.
For example, I have a List of Names that may contain many values such as (Ana, Ben, Maria, Ana). From this List, since the name Ana is listed twice, it should only be inserted in the database once, otherwise it will return an error. I know that the unique constraint can solve this, but is not the requirement in the current grails project that I am working on. So how will I compare the values of my list before inserting them to my database without using the unique constraint?
Please help!
Thanks!
Assuming you don’t mean you want to avoid the
uniquemethod in Groovy, you can do this:That creates a new list from
names(which is[ 'Ana', 'Ben', 'Maria' ]) and asserts it isn’t the same as the original list.It creates a new list as we passed
falseto theuniquemethod. If you passtrue, it will modify the original list…